From b178efed33a7758197dabd2aef0a4ee83407ae9e Mon Sep 17 00:00:00 2001 From: SeanvdMeer <18538762+minisean@users.noreply.github.com> Date: Sat, 21 Jun 2025 15:50:42 +0200 Subject: [PATCH] Added directional edge ID object --- .../connectivity/intrf_channel_identifier.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/qce_circuit/connectivity/intrf_channel_identifier.py b/src/qce_circuit/connectivity/intrf_channel_identifier.py index fceb75f..cdcb86c 100644 --- a/src/qce_circuit/connectivity/intrf_channel_identifier.py +++ b/src/qce_circuit/connectivity/intrf_channel_identifier.py @@ -321,3 +321,46 @@ def from_qubit_ids(cls, qubit_id0: QID, qubit_id1: QID) -> 'EdgeIDObj': qubit_id1=QubitIDObj(_id=qubit_id1), ) # endregion + + +@dataclass(frozen=True) +class DirectedEdgeIDObj(EdgeIDObj, IEdgeID): + """ + Data class, implementing (directed) IEdgeID interface. + """ + + # region Class Properties + @property + def from_qubit(self) -> IQubitID: + return self.qubit_id0 + + @property + def to_qubit(self) -> IQubitID: + return self.qubit_id1 + # endregion + + # region Class Methods + def __hash__(self): + """ + Sorts individual qubit hashes such that the order is NOT maintained. + Making hash comparison independent of order. + """ + return hash((self.qubit_id0.__hash__(), self.qubit_id1.__hash__())) + + def __eq__(self, other): + if isinstance(other, IEdgeID): + # Edge is equal if they share the same qubit identifiers, order does not matter + return other.__hash__() == self.__hash__() + return False + + def __repr__(self): + return f'{self.id}' + + @classmethod + def from_qubit_ids(cls, qubit_id0: QID, qubit_id1: QID) -> 'DirectedEdgeIDObj': + """:return: Class method constructor based on qubit-IDs.""" + return DirectedEdgeIDObj( + qubit_id0=QubitIDObj(_id=qubit_id0), + qubit_id1=QubitIDObj(_id=qubit_id1), + ) + # endregion