Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
4.83k stars 2.29k forks source link

GenericBackendV2 should fail when the backend cannot allocate the basis gate because its size #12653

Closed 1ucian0 closed 5 days ago

1ucian0 commented 6 days ago

Summary

GenericBackendV2 should not accept backends that are too small for certain gates. The following examples should be rejected:

GenericBackendV2(num_qubits=1, basis_gates=["cx", "id"])

GenericBackendV2(num_qubits=2, basis_gates=["ccx", "id"])

@ElePT found this!

qiskit-bot commented 6 days ago

One or more of the following people are relevant to this code:

coveralls commented 6 days ago

Pull Request Test Coverage Report for Build 9659396940

Details


Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 4 92.62%
crates/qasm2/src/parse.rs 18 96.69%
<!-- Total: 23 -->
Totals Coverage Status
Change from base Build 9650973845: -0.03%
Covered Lines: 63758
Relevant Lines: 71056

💛 - Coveralls
coveralls commented 6 days ago

Pull Request Test Coverage Report for Build 9663589789

Details


Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 6 91.6%
<!-- Total: 7 -->
Totals Coverage Status
Change from base Build 9661630219: 0.01%
Covered Lines: 63760
Relevant Lines: 71056

💛 - Coveralls
1ucian0 commented 6 days ago

am I allowed to approve?

It seems you are.

coveralls commented 6 days ago

Pull Request Test Coverage Report for Build 9663987131

Details


Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 4 92.37%
<!-- Total: 5 -->
Totals Coverage Status
Change from base Build 9661630219: 0.01%
Covered Lines: 63759
Relevant Lines: 71056

💛 - Coveralls
ElePT commented 6 days ago

I think we need to add an internal path for building a target for 1 qubit, because GenericBackendV2 contains 2q basis gates by default (that's why the test fails currently).

coveralls commented 6 days ago

Pull Request Test Coverage Report for Build 9667579174

Details


Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 6 92.62%
<!-- Total: 6 -->
Totals Coverage Status
Change from base Build 9661630219: 0.03%
Covered Lines: 63771
Relevant Lines: 71056

💛 - Coveralls
1ucian0 commented 5 days ago

I think we need to add an internal path for building a target for 1 qubit, because GenericBackendV2 contains 2q basis gates by default (that's why the test fails currently).

I think I prefer to keep the default simple (without different values depending on the number of qubits) and be explicit on the basis _gate (see https://github.com/Qiskit/qiskit/pull/12653/commits/43a94f1d79f72c482a38820ddef63df85836a0d0). What do you think?

ElePT commented 5 days ago

I think that can work too. If we see this is causing problems we can always correct the 1q path.

1ucian0 commented 5 days ago

@Mergifyio backport stable/0.46 stable/1.1

mergify[bot] commented 5 days ago

backport stable/0.46 stable/1.1

✅ Backports have been created

* [#12666 GenericBackendV2 should fail when the backend cannot allocate the basis gate because its size (backport #12653)](https://github.com/Qiskit/qiskit/pull/12666) has been created for branch `stable/0.46` but encountered conflicts * [#12667 GenericBackendV2 should fail when the backend cannot allocate the basis gate because its size (backport #12653)](https://github.com/Qiskit/qiskit/pull/12667) has been created for branch `stable/1.1`