Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document pyqrack target #6

Merged
merged 5 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 0 additions & 201 deletions src/bloqade/pyqrack/gate.py

This file was deleted.

75 changes: 0 additions & 75 deletions src/bloqade/pyqrack/measure.py

This file was deleted.

36 changes: 36 additions & 0 deletions src/bloqade/pyqrack/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@


class CRegister(list[bool]):
"""Runtime representation of a classical register."""

def __init__(self, size: int):
super().__init__(False for _ in range(size))


@dataclass(frozen=True)
class CBitRef:
"""Object representing a reference to a classical bit."""

ref: CRegister
"""The classical register that is holding this bit."""

pos: int
"""The position of this bit in the classical register."""

def set_value(self, value: bool):
self.ref[self.pos] = value
Expand All @@ -32,12 +39,27 @@ class QubitState(enum.Enum):

@dataclass(frozen=True)
class SimQReg(QReg, Generic[SimRegType]):
"""Simulation runtime value of a quantum register."""

size: int
"""The number of qubits in this register."""

sim_reg: SimRegType
"""The register of the simulator."""

addrs: tuple[int, ...]
"""The global addresses of the qubits in this register."""

qubit_state: List[QubitState]
"""The state of each qubit in this register."""

def drop(self, pos: int):
"""Drop the qubit at the given position in-place.

Args
pos (int): The position of the qubit to drop.

"""
assert self.qubit_state[pos] is QubitState.Active, "Qubit already lost"
self.qubit_state[pos] = QubitState.Lost

Expand All @@ -47,19 +69,33 @@ def __getitem__(self, pos: int):

@dataclass(frozen=True)
class SimQubit(Qubit, Generic[SimRegType]):
"""The runtime representation of a qubit reference."""

ref: SimQReg[SimRegType]
"""The quantum register that is holding this qubit."""

pos: int
"""The position of this qubit in the quantum register."""

@property
def sim_reg(self) -> SimRegType:
"""The register of the simulator."""
return self.ref.sim_reg

@property
def addr(self) -> int:
"""The global address of the qubit."""
return self.ref.addrs[self.pos]

def is_active(self) -> bool:
"""Check if the qubit is active.

Returns
True if the qubit is active, False otherwise.

"""
return self.ref.qubit_state[self.pos] is QubitState.Active

def drop(self):
"""Drop the qubit in-place."""
self.ref.drop(self.pos)
Loading