Closed Cryoris closed 3 days ago
One or more of the following people are relevant to this code:
@Cryoris
@Qiskit/terra-core
@ajavadia
@kevinhartman
@mtreinish
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.
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
crates/circuit/src/operations.rs | 72 | 81 | 88.89% | ||
<!-- | Total: | 106 | 115 | 92.17% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/circuit/src/operations.rs | 1 | 75.93% | ||
crates/qasm2/src/lex.rs | 4 | 91.86% | ||
<!-- | Total: | 5 | --> |
Totals | |
---|---|
Change from base Build 9648699798: | 0.02% |
Covered Lines: | 63847 |
Relevant Lines: | 71115 |
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
crates/circuit/src/operations.rs | 72 | 81 | 88.89% | ||
<!-- | Total: | 106 | 115 | 92.17% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/qasm2/src/expr.rs | 1 | 94.02% | ||
crates/circuit/src/operations.rs | 1 | 73.44% | ||
crates/qasm2/src/lex.rs | 4 | 92.62% | ||
crates/qasm2/src/parse.rs | 18 | 96.69% | ||
<!-- | Total: | 24 | --> |
Totals | |
---|---|
Change from base Build 9650973845: | -0.02% |
Covered Lines: | 63862 |
Relevant Lines: | 71167 |
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.
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
crates/circuit/src/operations.rs | 72 | 81 | 88.89% | ||
<!-- | Total: | 112 | 121 | 92.56% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/circuit/src/operations.rs | 1 | 73.44% | ||
crates/qasm2/src/lex.rs | 1 | 93.64% | ||
qiskit/circuit/quantumcircuit.py | 3 | 95.52% | ||
crates/qasm2/src/parse.rs | 12 | 97.15% | ||
<!-- | Total: | 17 | --> |
Totals | |
---|---|
Change from base Build 9650973845: | -0.006% |
Covered Lines: | 63876 |
Relevant Lines: | 71173 |
Picking up the ctrl_state
edge case @ElePT mentioned above, there is a potential sharp bit we're introducing with the change to Rust (this happens independently of the None
vs 1 "1"
discussion): changing the ctrl_state
of a mutable gate, like CRX, once the gate is in the circuit does not change the matrix anymore, but did before.
For example
from qiskit.quantum_info import Operator
from qiskit.circuit import QuantumCircuit
qc = QuantumCircuit(2)
qc.crx(2, 0, 1)
print(Operator(qc)) # matrix with ctrl_state 1
# not very legal but not explicitly illegal?
qc.data[0].operation.ctrl_state = 0
# w/o Rust gates this prints the correct matrix with ctrl_state 0,
# with Rust gates it still shows the matrix for ctrl_state 1
print(Operator(qc))
This may be something we need to fix globally.
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
crates/circuit/src/operations.rs | 72 | 81 | 88.89% | ||
<!-- | Total: | 112 | 121 | 92.56% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/circuit/src/operations.rs | 1 | 73.95% | ||
qiskit/circuit/quantumcircuit.py | 3 | 95.51% | ||
crates/qasm2/src/lex.rs | 6 | 92.37% | ||
<!-- | Total: | 10 | --> |
Totals | |
---|---|
Change from base Build 9683280067: | -0.001% |
Covered Lines: | 63922 |
Relevant Lines: | 71196 |
Picking up the
ctrl_state
edge case @ElePT mentioned above, there is a potential sharp bit we're introducing with the change to Rust (this happens independently of theNone
vs1 "1"
discussion): changing thectrl_state
of a mutable gate, like CRX, once the gate is in the circuit does not change the matrix anymore, but did before.For example
from qiskit.quantum_info import Operator from qiskit.circuit import QuantumCircuit qc = QuantumCircuit(2) qc.crx(2, 0, 1) print(Operator(qc)) # matrix with ctrl_state 1 # not very legal but not explicitly illegal? qc.data[0].operation.ctrl_state = 0 # w/o Rust gates this prints the correct matrix with ctrl_state 0, # with Rust gates it still shows the matrix for ctrl_state 1 print(Operator(qc))
This may be something we need to fix globally.
This sounds like a friend of:
gate.definition.global_phase = 3.14159
dag_node.op.params[0] = 3.14159
I don't think we'll be able to mutate any gate element post-Rust migration using that syntax (reno)
The other issue with ctrl_state
that I realized we're missing right now is what I pointed out here: https://github.com/Qiskit/qiskit/pull/12659#discussion_r1654466050 the handling in CircuitInstruction
's rust code for when you do CircuitInstruction(CRXGate(pi, ctrl_state=0), ...)
doesn't understand that CRXGate
with ctrl_state=0
is not the standard gate definition. We will need to update the logic in that function to check the value of ctrl_state
for a non-singleton controlled gate.
The other issue with
ctrl_state
that I realized we're missing right now is what I pointed out here: #12659 (comment) the handling inCircuitInstruction
's rust code for when you doCircuitInstruction(CRXGate(pi, ctrl_state=0), ...)
doesn't understand thatCRXGate
withctrl_state=0
is not the standard gate definition. We will need to update the logic in that function to check the value ofctrl_state
for a non-singleton controlled gate.
Yes, I am trying to fix it as part of #12659.
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
crates/circuit/src/operations.rs | 72 | 81 | 88.89% | ||
<!-- | Total: | 112 | 121 | 92.56% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/circuit/src/operations.rs | 1 | 73.76% | ||
qiskit/circuit/quantumcircuit.py | 3 | 95.51% | ||
crates/qasm2/src/lex.rs | 6 | 92.11% | ||
<!-- | Total: | 10 | --> |
Totals | |
---|---|
Change from base Build 9703107599: | 0.03% |
Covered Lines: | 63926 |
Relevant Lines: | 71211 |
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
crates/circuit/src/operations.rs | 72 | 81 | 88.89% | ||
<!-- | Total: | 112 | 121 | 92.56% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/circuit/src/operations.rs | 1 | 73.76% | ||
crates/qasm2/src/lex.rs | 2 | 92.88% | ||
qiskit/circuit/quantumcircuit.py | 3 | 95.51% | ||
<!-- | Total: | 6 | --> |
Totals | |
---|---|
Change from base Build 9714383578: | 0.006% |
Covered Lines: | 63915 |
Relevant Lines: | 71211 |
Summary
Port the controlled Pauli rotations to Rust. Checks off parts of #12566.