Source code for kosmos.protocols.protocol_result
from abc import ABC
from dataclasses import dataclass
import numpy as np
from kosmos.protocols.routing.path import Path
from kosmos.protocols.status import ProtocolStatus
[docs]
@dataclass
class ProtocolResult(ABC):
"""Result of protocol execution.
Attributes:
status (ProtocolStatus): Status of the protocol.
"""
status: ProtocolStatus
[docs]
@dataclass
class CommunicationProtocolResult(ProtocolResult):
"""Communication protocol result.
Attributes:
status (ProtocolStatus): Status of the protocol.
execution_time (int | None): Required time to generate entanglement.
"""
execution_time: int | None = None
[docs]
@dataclass
class RoutingProtocolResult(ProtocolResult):
"""Routing protocol result.
Attributes:
status (ProtocolStatus): Status of the protocol.
path (Path | None): Resulting path of the routing protocol. None if no path was found.
total_cost (float | None): Total cost of the resulting path. None if no path was found.
total_distance (float | None): Total distance of the resulting path. None if no path was
found.
"""
path: Path | None
total_cost: float | None
total_distance: float | None
def __str__(self) -> str:
"""Return a human-readable string with the path and metrics formatted to four decimals."""
desc = ""
if self.path is not None:
desc += "Path: " + str(self.path) + "\n"
else:
return "No path found."
if self.total_cost is not None:
desc += f"Total cost: {self.total_cost:.4g}\n"
if self.total_distance is not None:
desc += f"Total distance: {self.total_distance:.4f}\n"
return desc.strip()
[docs]
@dataclass
class CircuitExecutionProtocolResult(ProtocolResult):
"""Circuit execution protocol result.
Attributes:
status (ProtocolStatus): Status of the protocol.
execution_time (int): Time (in picoseconds) taken to complete the operation. Defaults to 0.
density_matrix (np.ndarray | None): Density matrix at the end of the circuit.
Defaults to None.
"""
execution_time: int = 0
density_matrix: np.ndarray | None = None