Closed mtreinish closed 5 days ago
One or more of the following people are relevant to this code:
@Qiskit/terra-core
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
qiskit/circuit/quantumcircuit.py | 3 | 4 | 75.0% | ||
<!-- | Total: | 3 | 4 | 75.0% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/qasm2/src/expr.rs | 1 | 94.02% | ||
crates/qasm2/src/lex.rs | 5 | 91.6% | ||
<!-- | Total: | 6 | --> |
Totals | |
---|---|
Change from base Build 9661630219: | 0.01% |
Covered Lines: | 63759 |
Relevant Lines: | 71056 |
It showed up in py-spy profiling I was doing of permutation synthesis. It wasn't a major component but I was surprised to see it there so I pushed this up to fix it. A dict comprehension is a good idea and will make it a bit faster, I'll tweak this shortly.
This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/qasm2/src/expr.rs | 1 | 94.02% | ||
qiskit/synthesis/discrete_basis/solovay_kitaev.py | 4 | 94.74% | ||
crates/qasm2/src/lex.rs | 6 | 91.86% | ||
qiskit/providers/fake_provider/generic_backend_v2.py | 10 | 94.71% | ||
<!-- | Total: | 21 | --> |
Totals | |
---|---|
Change from base Build 9661630219: | 0.02% |
Covered Lines: | 63768 |
Relevant Lines: | 71062 |
Summary
This commit simplifies the logic around bit handling in the
QuantumCircuit._from_circuit_data()
constructor. Previously it was callingadd_bits()
for each bit in theCircuitData
object to update the output circuit's accounting for each qubit. But this was needlessly heavy as theCircuitData
is already the source of truth for the bits in a circuit and we just need to update the indices dictionary. Theadd_bits()
method attempts to add the bits to theCircuitData
too but this is wasted overhead because theCircuitData
already has the bits as that's where the came from. This changes the constructor to just directly set the bit indices as needed and return the circuit.Details and comments