Skip to content

Commit

Permalink
the simulator loading bar will now no longer count deallocated qubits
Browse files Browse the repository at this point in the history
  • Loading branch information
positr0nium committed Dec 22, 2024
1 parent f71e540 commit a7f93ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ def flatten_environments_in_while_eqn(eqn, context_dic):
"""

eqn = copy_jaxpr_eqn(eqn)

eqn.params["body_jaxpr"] = ClosedJaxpr(flatten_environments(eqn.params["body_jaxpr"].jaxpr),
eqn.params["body_jaxpr"].consts)


exec_eqn(eqn, context_dic)

Expand Down
12 changes: 9 additions & 3 deletions src/qrisp/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,12 @@ def pre_calc_unitaries(op):

return "".join(result_str)[::-1], quantum_state

def advance_quantum_state(qc, quantum_state):
def advance_quantum_state(qc, quantum_state, deallocated_qubits = []):
if len(qc.data) == 0:
return quantum_state

progress_bar = tqdm(
desc=f"Simulating {len(qc.qubits)} qubits..",
desc=f"Simulating {len(qc.qubits)-len(deallocated_qubits)} qubits..",
bar_format="{desc} |{bar}| [{percentage:3.0f}%]",
ncols=85,
leave=False,
Expand All @@ -420,6 +420,10 @@ def advance_quantum_state(qc, quantum_state):

LINE_CLEAR = "\x1b[2K"
progress_bar.display()

for instr in qc.data:
if instr.op.name == "qb_dealloc":
deallocated_qubits.append(instr.qubits[0])

# This command enables fast appending. Fast appending means that the .append method
# of the QuantumCircuit class checks much less validity conditions and is also less
Expand Down Expand Up @@ -490,6 +494,7 @@ def __init__(self):

self.quantum_state = QuantumState(n = 0)
self.buffer_qc = QuantumCircuit(0)
self.deallocated_qubits = []

def add_qubit(self):
self.quantum_state.add_qubit()
Expand All @@ -499,7 +504,8 @@ def append(self, op, qubits):
self.buffer_qc.append(op, qubits)

def apply_buffer(self):
self.quantum_state = advance_quantum_state(self.buffer_qc, self.quantum_state)

self.quantum_state = advance_quantum_state(self.buffer_qc, self.quantum_state, self.deallocated_qubits)
self.buffer_qc = self.buffer_qc.clearcopy()

def measure(self, qubit):
Expand Down

0 comments on commit a7f93ac

Please sign in to comment.