-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
raise an exception with a custom gate with clbits or no qubits #10438
Conversation
before adding tests and reno, @jakelishman do you think adding this limitation makes sense? |
Pull Request Test Coverage Report for Build 5643565062
💛 - Coveralls |
qiskit/circuit/quantumcircuit.py
Outdated
# Gate definitions with 0 qubits or with any classical bits are not allowed. | ||
if operation.num_qubits == 0 or operation.num_clbits != 0: | ||
raise CircuitError( | ||
"OpenQASM 2 does not allow gate definitions with no qubits or with any " | ||
f"classical bit: '{operation.name}' has {operation.num_qubits} qubits " | ||
f"and {operation.num_clbits} clbits" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error should be QASM2ExportError
, but otherwise this is fine.
Not sure the comment is needed, since the error message says the exact same thing ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks! done in fc0d3be
One or more of the the following people are requested to review this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this Luciano. I quickly separated out the two failure paths to improve the error message and fixed the test (measure_all
adds a new register), but this is good to go.
Aren't you meant to be on holiday?
* raise an exception with a custom gate with no qubits or with one-or-more clbits * QASM2ExportError * test_circuit_raises_invalid_custom_gate_1 * test_circuit_raises_invalid_custom_gate_2 * reno * Split error messages to be more specific * Fix testing bug * Fixup release note --------- Co-authored-by: Jake Lishman <jake.lishman@ibm.com> (cherry picked from commit 208c29a)
thank you @1ucian0 @jakelishman |
… (#10485) * raise an exception with a custom gate with no qubits or with one-or-more clbits * QASM2ExportError * test_circuit_raises_invalid_custom_gate_1 * test_circuit_raises_invalid_custom_gate_2 * reno * Split error messages to be more specific * Fix testing bug * Fixup release note --------- Co-authored-by: Jake Lishman <jake.lishman@ibm.com> (cherry picked from commit 208c29a) Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
…t#10438) * raise an exception with a custom gate with no qubits or with one-or-more clbits * QASM2ExportError * test_circuit_raises_invalid_custom_gate_1 * test_circuit_raises_invalid_custom_gate_2 * reno * Split error messages to be more specific * Fix testing bug * Fixup release note --------- Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Fixes #10435
Fix #7351
Currently, OpenQASM 2 exporter dumps invalid code when a custom gate has no qubits or has classical wires involved.
The no-qubit case it is considered invalid by the OpenQASM 2 grammar:
I think the case of
<id>
referring to classical wires can be inferred from the name of the statement:gate
, as in a quantum gate.