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

Fix performance issue in parsing bit indices in QPY (backport #11944) #11945

Merged
merged 1 commit into from
Mar 4, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 2 additions & 9 deletions qiskit/qpy/binary_io/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,6 @@ def _read_instruction(
cregs=registers["c"],
use_symengine=use_symengine,
)
if circuit is not None:
qubit_indices = dict(enumerate(circuit.qubits))
clbit_indices = dict(enumerate(circuit.clbits))
else:
qubit_indices = {}
clbit_indices = {}

# Load Arguments
if circuit is not None:
for _qarg in range(instruction.num_qargs):
Expand All @@ -243,7 +236,7 @@ def _read_instruction(
)
if qarg.type.decode(common.ENCODE) == "c":
raise TypeError("Invalid input carg prior to all qargs")
qargs.append(qubit_indices[qarg.size])
qargs.append(circuit.qubits[qarg.size])
for _carg in range(instruction.num_cargs):
carg = formats.CIRCUIT_INSTRUCTION_ARG._make(
struct.unpack(
Expand All @@ -253,7 +246,7 @@ def _read_instruction(
)
if carg.type.decode(common.ENCODE) == "q":
raise TypeError("Invalid input qarg after all qargs")
cargs.append(clbit_indices[carg.size])
cargs.append(circuit.clbits[carg.size])

# Load Parameters
for _param in range(instruction.num_parameters):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a performance issue in the :func:`.qpy.load` function when
deserializing QPY payloads with large numbers of qubits or clbits in
a circuit.