-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add Statevector.from_instruction
to mirror Operator.from_instruction
#13621
Comments
The output of the code above:
|
This is expected behaviour - we perform the swaps virtually as part of the transpilation at higher optimisation levels, and this is reflected in the output layout of the circuit. See more discussion in #12440, for example. |
Thank you for the answer. Does that mean if I want to get a consistent vector numerics for any arbitrary optimization levels, instead of doing sv = Statevector(circuit) I do sv2 = Statevector(QuantumCircuit(transpiled2.num_qubits))
transpiled2_unitary = Operator.from_circuit(transpiled2)
sv2 = sv2.evolve(transpiled2_unitary) ? |
If we don't already have In general, compilation involves changing the Hilbert space the circuit is defined in - typically we go from virtual to physical qubits. The two spaces might be isomorphic, but they don't necessarily need to be, and to satisfy hardware coupling constraints, even in the isomorphic case we have to change the bimap over the course of circuit execution. In this case, you're trying to think about the Hilbert spaces as being unchanged, but that's not how we approach compilation - the use of compiled output in simulators is a side-effect for us, where the first priority is optimising the output quality for hardware execution. Hopefully a Fwiw, I think setting |
I see your point regarding prioritizing for the hardware execution over the consistency of the qubit labels in the abstract layout. But I often use the However, I'm fine with a
I tested this, and it worked. It sure is simpler. |
This expectation is making a tacit assumption that qubit 0 is measured into clbit 0, etc - there wouldn't be a bitstring at all without a measurement. If we don't have clbits and measurements to fix the observability, it comes down to my Hilbert space problem again. There still is a proper isomorphism between the input virtual qubits and the output qubits in this case (though in general those two spaces don't need to be isomorphic - for example, we could reuse the same physical qubit for two different virtual qubits if the state lifetimes don't overlap), but we don't require that the implicit qubits indices are equal between those two things. Let me tag this as a feature request to add |
Statevector.from_instruction
to mirror Operator.from_instruction
Environment
Also relevant:
What is happening?
The error comes from a randomly generated circuit in our repo when we tried to bump to Qiskit 1.3.1. It appears that bumping NumPy from 1.x to 2.0 had resulted in a different random circuit in our test suite (even though they had been made deterministic via pytest seeds). I tried downgrading all the way to Qiskit 1.1.2, and the statevector discrepancy still happens.
How can we reproduce the issue?
What should happen?
The statevectors should have been equivalent up to a global phase, but they aren't.
Any suggestions?
No response
The text was updated successfully, but these errors were encountered: