Skip to content
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

Fix converting VectorStateFn to a CircuitStateFn #8405

Merged
merged 1 commit into from
Jul 27, 2022

Conversation

Cryoris
Copy link
Contributor

@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, manoelmarques, woodsp-ibm and ikkoham 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 The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the 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: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants