diff --git a/lib_q_computer_math.py b/lib_q_computer_math.py index 5cb1e7c..585cd38 100644 --- a/lib_q_computer_math.py +++ b/lib_q_computer_math.py @@ -541,15 +541,6 @@ class QuantumCircuit(object): for row_data in rows_data: self.add_row(row_data) - def get_next_step(self): - running_step = self.steps[self.c_step] - step_quantum_state = self.compose_quantum_state(running_step) - if not self.c_q_state: - self.c_q_state = step_quantum_state - else: - self.c_q_state = State((step_quantum_state | self.c_q_state).m) - self.c_step += 1 - def print(self): print("=" * 3 * len(self.steps)) for line_no in range(self.n_qubits): @@ -588,18 +579,22 @@ class QuantumProcessor(object): if self.c_step >= len(self.circuit.steps): self.c_state = self.HALT_STATE raise RuntimeWarning("Halted") - running_step = self.circuit.get_next_step() - step_quantum_state = self.compose_quantum_state(running_step) + step_quantum_state = self.get_next_step() if not self.c_q_state: self.c_q_state = step_quantum_state else: self.c_q_state = State((step_quantum_state | self.c_q_state).m) self.c_step += 1 + def get_next_step(self): + running_step = self.circuit.steps[self.c_step] + step_quantum_state = self.compose_quantum_state(running_step) + return step_quantum_state + def run(self): - for _ in self.steps: + for _ in self.circuit.steps: self.step() - self.current_state = self.HALT_STATE + self.c_state = self.HALT_STATE def reset(self): self.c_step = 0 @@ -632,11 +627,12 @@ class QuantumProcessor(object): def test_quantum_processor(): # Produce Bell state between 0 and 2 qubit - qp = QuantumProcessor(3) - qp.add_row([H, C]) - qp.add_row([_, _]) - qp.add_row([_, x]) - qp.print() + qc = QuantumCircuit(3) + qc.add_row([H, C]) + qc.add_row([_, _]) + qc.add_row([_, x]) + qc.print() + qp = QuantumProcessor(qc) qp.get_sample(100)