11import enum
2- from typing import TYPE_CHECKING , List
2+ from typing import TYPE_CHECKING
33from dataclasses import dataclass
44
5- from bloqade .qasm2 .types import QReg , Qubit
5+ from bloqade .qasm2 .types import Qubit
66
77if TYPE_CHECKING :
88 from pyqrack import QrackSimulator
@@ -45,57 +45,18 @@ class QubitState(enum.Enum):
4545 Lost = enum .auto ()
4646
4747
48- @dataclass (frozen = True )
49- class PyQrackReg (QReg ): # TODO: clean up implementation with list base class
50- """Simulation runtime value of a quantum register."""
51-
52- size : int
53- """The number of qubits in this register."""
54-
55- sim_reg : "QrackSimulator"
56- """The register of the simulator."""
57-
58- addrs : tuple [int , ...]
59- """The global addresses of the qubits in this register."""
60-
61- qubit_state : List [QubitState ]
62- """The state of each qubit in this register."""
63-
64- def drop (self , pos : int ):
65- """Drop the qubit at the given position in-place.
66-
67- Args
68- pos (int): The position of the qubit to drop.
69-
70- """
71- assert self .qubit_state [pos ] is QubitState .Active , "Qubit already lost"
72- self .qubit_state [pos ] = QubitState .Lost
73-
74- def __getitem__ (self , pos : int ):
75- if not 0 <= pos < self .size :
76- raise IndexError ("Qubit index out of bounds of register." )
77- return PyQrackQubit (self , pos )
78-
79-
80- @dataclass (frozen = True )
48+ @dataclass
8149class PyQrackQubit (Qubit ):
8250 """The runtime representation of a qubit reference."""
8351
84- ref : PyQrackReg
85- """The quantum register that is holding this qubit ."""
52+ addr : int
53+ """The address of this qubit in the quantum register ."""
8654
87- pos : int
88- """The position of this qubit in the quantum register."""
89-
90- @property
91- def sim_reg (self ):
92- """The register of the simulator."""
93- return self .ref .sim_reg
55+ sim_reg : "QrackSimulator"
56+ """The register of the simulator."""
9457
95- @property
96- def addr (self ) -> int :
97- """The global address of the qubit."""
98- return self .ref .addrs [self .pos ]
58+ state : QubitState
59+ """The state of the qubit (active/lost)"""
9960
10061 def is_active (self ) -> bool :
10162 """Check if the qubit is active.
@@ -104,8 +65,8 @@ def is_active(self) -> bool:
10465 True if the qubit is active, False otherwise.
10566
10667 """
107- return self .ref . qubit_state [ self . pos ] is QubitState .Active
68+ return self .state is QubitState .Active
10869
10970 def drop (self ):
11071 """Drop the qubit in-place."""
111- self .ref . drop ( self . pos )
72+ self .state = QubitState . Lost
0 commit comments