Skip to content

Commit

Permalink
Some tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-mills-cqc committed Jun 14, 2024
1 parent 860ff95 commit abc09bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 58 deletions.
60 changes: 20 additions & 40 deletions pytket-mbqc-py/pytket_mbqc_py/graph_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ class GraphCircuit(RandomRegisterManager):
:ivar vertex_qubit: List mapping graph vertex to corresponding qubits.
:ivar vertex_measured: List indicating if vertex has been measured.
:ivar vertex_reg: List mapping vertex to the its register.
In particular this is a 5 bit register
with the 0th entry storing the measurement result, the 1s giving the T rotation, the 2nd giving the
S rotation, and the 3rd giving the Z rotation, and the 4th storing the X correction.
In particular this is a 5 bit register with the 0th entry storing
the measurement result, the 1st giving the random T rotation, the 2nd
giving the S rotation, the 3rd giving the Z rotation, and
the 4th storing the X correction.
:ivar measurement_order_list: List of vertex measurement order.
Entry i corresponds to the position in the order at which
vertex i is measured. If None then vertex is taken not to be
Expand Down Expand Up @@ -64,30 +65,23 @@ def __init__(

self.measurement_order_list = []

# We need to save the x correction information long term.
# This is why there is one register per vertex, as these
# values cannot be overwritten. They are saved long term
# as they are needed to calculate z corrections on
# neighbouring qubits, which could be needed after the
# vertex has been measured.
# self.vertex_x_corr_reg = []

# Generate one random register per vertex.
# When qubits are added they will be initialised in this
# random register. This is except for the case of input qubits
# which are initialised in the 0 state, and in which case this
# register is overwritten.
# self.vertex_init_reg = self.generate_random_registers(
# n_registers=n_logical_qubits
# )

# There is one register per vertex.
# The bits in the register are as follows:
# - 0 : Storage for measurement results.
# - 1 : First random initialisation bit.
# - 2 : Second random initialisation bit.
# - 3 : Third random initialisation bit.
# - 4 : X correction register.
# When qubits are added they will be initialised in this
# random register. This is except for the case of input qubits
# which are initialised in the 0 state, and in which case this
# register is overwritten.
# We need to save the x correction information long term.
# This is why there is one register per vertex, as these
# values cannot be overwritten. They are saved long term
# as they are needed to calculate z corrections on
# neighbouring qubits, which could be needed after the
# vertex has been measured.
self.vertex_reg = [
self.add_c_register(
name=f'vertex_{vertex_index}',
Expand Down Expand Up @@ -197,7 +191,7 @@ def get_outputs(self) -> Dict[int, Qubit]:

return output_qubits

def _add_vertex(self, qubit: Qubit, measurement_order: Union[int, None]) -> int:
def _add_vertex(self, qubit: Qubit, measurement_order: Union[int, None]) -> None:
"""Add a new vertex to the graph.
This requires that the vertex is added to the
entanglement and flow graphs. A register to save
Expand All @@ -213,16 +207,10 @@ def _add_vertex(self, qubit: Qubit, measurement_order: Union[int, None]) -> int:
self.entanglement_graph.add_node(node_for_adding=index)
self.flow_graph.add_node(node_for_adding=index)

# x_corr_reg = BitRegister(name=f"x_corr_{index}", size=1)
# self.add_c_register(register=x_corr_reg)

# self.vertex_x_corr_reg.append(x_corr_reg)
self.vertex_qubit.append(qubit)
self.vertex_measured.append(False)
self.measurement_order_list.append(measurement_order)

# return index

def add_input_vertex(
self, measurement_order: Union[int, None]
) -> Tuple[Qubit, int]:
Expand Down Expand Up @@ -476,18 +464,11 @@ def _apply_classical_z_correction(self, vertex: int) -> None:
:param vertex: Vertex to be corrected.
"""
condition = self._get_z_correction_expression(vertex=vertex)
# if condition is not None:
# self.add_classicalexpbox_bit(
# expression=self.qubit_meas_reg[self.vertex_qubit[vertex]][0]
# ^ condition,
# target=[self.qubit_meas_reg[self.vertex_qubit[vertex]][0]],
# )
if condition is not None:
self.add_classicalexpbox_bit(
expression=self.vertex_reg[vertex][0]
^ condition,
target=[self.vertex_reg[vertex][0]],
)
self.add_classicalexpbox_bit(
expression=self.vertex_reg[vertex][0]
^ condition,
target=[self.vertex_reg[vertex][0]],
)

def corrected_measure(self, vertex: int, t_multiple: int = 0) -> None:
"""Perform a measurement, applying the appropriate corrections.
Expand Down Expand Up @@ -577,7 +558,6 @@ def corrected_measure(self, vertex: int, t_multiple: int = 0) -> None:

# Apply X correction according to correction register.
# This is to correct for measurement outcomes.
# print(self.vertex_reg[vertex].to_list())
self.X(
self.vertex_qubit[vertex],
condition=self.vertex_reg[vertex][4],
Expand Down
18 changes: 0 additions & 18 deletions pytket-mbqc-py/pytket_mbqc_py/qubit_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class QubitManager(Circuit):

available_qubit_list: List[Qubit]
all_qubit_list: List[Qubit]
# qubit_meas_reg: Dict[Qubit, BitRegister]
physical_qubits_used: set[Qubit]

def __init__(self, n_physical_qubits: int) -> None:
Expand All @@ -38,20 +37,11 @@ def __init__(self, n_physical_qubits: int) -> None:
"""
self.available_qubit_list = [Qubit(index=i) for i in range(n_physical_qubits)]
self.all_qubit_list = [Qubit(index=i) for i in range(n_physical_qubits)]
# self.qubit_meas_reg = {
# qubit: BitRegister(name=f"meas_{i}", size=1)
# for i, qubit in enumerate(self.available_qubit_list)
# }
self.qubit_meas_bit = dict()
self.physical_qubits_used = set()

# self.qubits_created = 0

super().__init__()

# for meas_reg in self.qubit_meas_reg.values():
# self.add_c_register(register=meas_reg)

for qubit in self.all_qubit_list:
self.add_qubit(id=qubit)

Expand All @@ -67,17 +57,10 @@ def get_qubit(self, measure_bit: Bit) -> Qubit:

qubit = self.available_qubit_list.pop(0)
self.physical_qubits_used.add(qubit)
# self.qubit_meas_reg[qubit] = self.add_c_register(
# name=f'meas_{self.qubits_created}', size=1
# )
self.qubit_meas_bit[qubit] = measure_bit
# self.add_c_setreg(0, self.qubit_meas_reg[qubit])
# print(self.qubit_meas_bit[qubit])
self.add_c_setbits([0], [self.qubit_meas_bit[qubit]])
self.Reset(qubit=qubit)

# self.qubits_created += 1

return qubit

def managed_measure(self, qubit: Qubit) -> None:
Expand All @@ -101,5 +84,4 @@ def managed_measure(self, qubit: Qubit) -> None:
+ "get_qubit method."
)
self.available_qubit_list.insert(0, qubit)
# self.Measure(qubit=qubit, bit=self.qubit_meas_reg[qubit][0])
self.Measure(qubit=qubit, bit=self.qubit_meas_bit[qubit])

0 comments on commit abc09bd

Please sign in to comment.