Warning on `add_bits` with layout information
Summary
The method add_bits does not check if the circuit has layout information. The layout information is not updated when the method add_bits is called by a circuit already having layout information. A warning is added to inform if a circuit has
layout information.
Details and comments
A UserWarning provided to add_bits in quantumcircuit.py.
One or more of the following people are relevant to this code:
@Qiskit/terra-core
Pull Request Test Coverage Report for Build 16872034759
Details
- 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
- 3 unchanged lines in 3 files lost coverage.
- Overall coverage increased (+0.04%) to 87.692%
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| crates/circuit/src/parameter/symbol_expr.rs | 1 | 74.74% |
| crates/qasm2/src/expr.rs | 1 | 93.63% |
| crates/qasm2/src/lex.rs | 1 | 92.27% |
| <!-- | Total: | 3 |
| Totals | |
|---|---|
| Change from base Build 16837695320: | 0.04% |
| Covered Lines: | 82389 |
| Relevant Lines: | 93953 |
💛 - Coveralls
Thanks for this Kalyan. We should also add a test that the warning is raised, both for directly adding qubits, for adding them implicitly via
add_register(QuantumRegister), and also that the warning isn't raised if you only add clbits (which aren't in the layout).I think the warning could perhaps be clearer about why it's a problem, and we might want to document in
add_bitswhy it's a problem to add qubits to circuit that's been laid out.Currently in the implementation, we warn but continue, which leaves the circuit in an invalid state. I'm actually thinking now: perhaps this ought to be an exception, not a warning? You need to do
QuantumCircuit.layout = Nonebefore adding bits, or you're invalidating the coherence?
Added documentation and test cases as suggested.
Thanks Kalyan - this looks sensible, the review's just minor wording stuff then it's mergeable.
Thanks a lot for the review @jakelishman. I have made all the changes you recommended.