refactor quantum circuit
This commit is contained in:
parent
a09bdb949c
commit
b6e256a3a7
@ -541,15 +541,6 @@ class QuantumCircuit(object):
|
|||||||
for row_data in rows_data:
|
for row_data in rows_data:
|
||||||
self.add_row(row_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):
|
def print(self):
|
||||||
print("=" * 3 * len(self.steps))
|
print("=" * 3 * len(self.steps))
|
||||||
for line_no in range(self.n_qubits):
|
for line_no in range(self.n_qubits):
|
||||||
@ -588,18 +579,22 @@ class QuantumProcessor(object):
|
|||||||
if self.c_step >= len(self.circuit.steps):
|
if self.c_step >= len(self.circuit.steps):
|
||||||
self.c_state = self.HALT_STATE
|
self.c_state = self.HALT_STATE
|
||||||
raise RuntimeWarning("Halted")
|
raise RuntimeWarning("Halted")
|
||||||
running_step = self.circuit.get_next_step()
|
step_quantum_state = self.get_next_step()
|
||||||
step_quantum_state = self.compose_quantum_state(running_step)
|
|
||||||
if not self.c_q_state:
|
if not self.c_q_state:
|
||||||
self.c_q_state = step_quantum_state
|
self.c_q_state = step_quantum_state
|
||||||
else:
|
else:
|
||||||
self.c_q_state = State((step_quantum_state | self.c_q_state).m)
|
self.c_q_state = State((step_quantum_state | self.c_q_state).m)
|
||||||
self.c_step += 1
|
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):
|
def run(self):
|
||||||
for _ in self.steps:
|
for _ in self.circuit.steps:
|
||||||
self.step()
|
self.step()
|
||||||
self.current_state = self.HALT_STATE
|
self.c_state = self.HALT_STATE
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.c_step = 0
|
self.c_step = 0
|
||||||
@ -632,11 +627,12 @@ class QuantumProcessor(object):
|
|||||||
|
|
||||||
def test_quantum_processor():
|
def test_quantum_processor():
|
||||||
# Produce Bell state between 0 and 2 qubit
|
# Produce Bell state between 0 and 2 qubit
|
||||||
qp = QuantumProcessor(3)
|
qc = QuantumCircuit(3)
|
||||||
qp.add_row([H, C])
|
qc.add_row([H, C])
|
||||||
qp.add_row([_, _])
|
qc.add_row([_, _])
|
||||||
qp.add_row([_, x])
|
qc.add_row([_, x])
|
||||||
qp.print()
|
qc.print()
|
||||||
|
qp = QuantumProcessor(qc)
|
||||||
qp.get_sample(100)
|
qp.get_sample(100)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user