Skip to content

Fix converting VectorStateFn to a CircuitStateFn#8405

Merged
mergify[bot] merged 1 commit intoQiskit:mainfrom
Cryoris:fix-vectorfn-to-circuitfn
Jul 27, 2022
Merged

Fix converting VectorStateFn to a CircuitStateFn#8405
mergify[bot] merged 1 commit intoQiskit:mainfrom
Cryoris:fix-vectorfn-to-circuitfn

Conversation

@Cryoris
Copy link
Collaborator

@Cryoris Cryoris commented Jul 27, 2022

Summary

Fix converting a VectorStateFn to a CircuitStateFn, which previously resulted in a StateFn that couldn't be adjoint.

Details and comments

Previously it was not possible to adjoint a CircuitStateFn that has been
constructed from a VectorStateFn, because the statevector has been
converted to a circuit with the Initialize instruction, which
is not unitary. This problem is now fixed by instead using the 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 also enables using initial states in #8304.

@Cryoris Cryoris requested review from a team, ikkoham, manoelmarques and woodsp-ibm as code owners July 27, 2022 13:53
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

@mtreinish mtreinish added stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge. Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. automerge labels Jul 27, 2022
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2747142077

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 83.994%

Totals Coverage Status
Change from base Build 2745932216: 0.007%
Covered Lines: 55897
Relevant Lines: 66549

💛 - Coveralls

@mergify mergify bot merged commit 625ff98 into Qiskit:main Jul 27, 2022
mergify bot pushed a commit that referenced this pull request Jul 27, 2022
mergify bot added a commit that referenced this pull request Jul 27, 2022
(cherry picked from commit 625ff98)

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants