forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix converting VectorStateFn to a CircuitStateFn (Qiskit#8405)
- Loading branch information
Showing
3 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
releasenotes/notes/fix-opflow-vector-to-circuit-fn-02cb3424269fa733.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
fixes: | ||
- | | ||
Previously it was not possible to adjoint a :class:`.CircuitStateFn` that has been | ||
constructed from a :class:`.VectorStateFn`. That's because the statevector has been | ||
converted to a circuit with the :class:`~qiskit.extensions.Initialize` instruction, which | ||
is not unitary. This problem is now fixed by instead using the :class:`.StatePreparation` | ||
instruction, which can be used since the state is assumed to start out in the all 0 state. | ||
For example we can now do:: | ||
from qiskit import QuantumCircuit | ||
from qiskit.opflow import StateFn | ||
left = StateFn([0, 1]) | ||
left_circuit = left.to_circuit_op().primitive | ||
right_circuit = QuantumCircuit(1) | ||
right_circuit.x(0) | ||
overlap = left_circuit.inverse().compose(right_circuit) # this line raised an error before! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters