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

Support for time-dependent Hamiltonians and observable evaluation in TrotterQRTE #9565

Merged
merged 18 commits into from
Feb 13, 2023

Conversation

Durd3nT
Copy link
Contributor

@Durd3nT Durd3nT commented Feb 10, 2023

Summary

This PR adds two features to the TrotterQRTE class.

  1. it adds support for time-dependent Hamiltonians (i.e., singly parametrized operators)
  2. it extends the evaluation of aux_operators to every timestep.

Details and comments

The above is achieved by constructing the full circuit of a Trotterized time evolution within TrotterQRTE instead of (as was previously the case) in PauliEvolutionGate.
Previously, the number of timesteps was passed to the ProductFormula through the reps argument. PauliEvolutionGate was then called from TrotterQRTE to construct the full circuit corresponding to the full time evolution.
Instead, now TrotterQRTE accepts the argument num_timesteps (analogous to VarQTE). The PauliEvolutionGate is only used to construct a single repetition of a product formula circuit and these single-step evolution gates are chained together in TrotterQRTE.evolve.
This has two benefits:

  1. parameter values (the time at the current timestep) can be bound to the Hamiltonian at every time step, allowing to the construction of evolution gates of time-dependent Hamiltonians.
  2. aux_operators can be evaluated at every timestep, which is the natural application for any time evolution algorithm.

Since SparsePauliOp does not yet support parameter-assignments, parameter values are assigned to the Hamiltonian at each time step through the helper function _assign_parameters. For this purpose, this helper function was moved to a higher level in the hierarchy of the Algorithms module and the import in VarQTE was adapted.
In the future, a method SparsePauliOp.assign_parameters should be added.

…erization.TrotterQRTE with synthesis LieTrotter
…ormula-classes unchanged wrt main. Also added evaluation of auxiliary_operators at every time-step of TrotterQRTE
…ormula-classes unchanged wrt main. Also added evaluation of auxiliary_operators at every time-step of TrotterQRTE
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Feb 10, 2023
@CLAassistant
Copy link

CLAassistant commented Feb 10, 2023

CLA assistant check
All committers have signed the CLA.

@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:

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, I left some comments below. The main suggestions are

  • keeping aux_ops_evaluated as is and instead introduce observables
  • don't change the product formula but apply it as the user supplied it

Could also add a releasenote for this new feature? 🙂

qiskit/synthesis/evolution/lie_trotter.py Outdated Show resolved Hide resolved
test/python/algorithms/time_evolvers/test_trotter_qrte.py Outdated Show resolved Hide resolved
test/python/algorithms/time_evolvers/test_trotter_qrte.py Outdated Show resolved Hide resolved
)
estimator = Estimator()

expected_evolved_state = Statevector([0.90201212+0.12857871j, 0.05815816+0.40799421j])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these numbers coming from? 🙂 Would it be possible to have a manual calculation as reference? 😄

qiskit/circuit/library/pauli_evolution.py Show resolved Hide resolved
@Cryoris Cryoris added Changelog: New Feature Include in the "Added" section of the changelog mod: algorithms Related to the Algorithms module labels Feb 10, 2023
@woodsp-ibm
Copy link
Member

One more of a procedural comment is that ideally the copyright dates on these changed files should be updated for 2023,

Eg (C) Copyright IBM 2021, 2022. would become (C) Copyright IBM 2021, 2023. where the last date of copyright is changed to the current year - the format is first date, last date but is they are the same its just put once. So if its a single date now, and not 2023, eg (C) Copyright IBM 2021. it would become (C) Copyright IBM 2021, 2023.

Durd3nT and others added 6 commits February 10, 2023 21:44
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
…lse, copies parameter array and returns new bound array leaving the passed array untouched
@Cryoris Cryoris changed the title TrotterQRTE: support for time-dependent Hamiltonians and evaluate aux_ops at every time step Support for time-dependent Hamiltonians and observable evaluation in TrotterQRTE Feb 13, 2023
Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding these features!

@mergify mergify bot merged commit 41e0c3a into Qiskit:main Feb 13, 2023
@coveralls
Copy link

Pull Request Test Coverage Report for Build 4164041180

  • 47 of 50 (94.0%) changed or added relevant lines in 4 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.002%) to 85.272%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/algorithms/utils/assign_params.py 8 9 88.89%
qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py 34 36 94.44%
Files with Coverage Reduction New Missed Lines %
src/vf2_layout.rs 1 86.44%
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 93.97%
Totals Coverage Status
Change from base Build 4162466886: -0.002%
Covered Lines: 67267
Relevant Lines: 78885

💛 - Coveralls

nbronn pushed a commit to nbronn/qiskit-terra that referenced this pull request Feb 13, 2023
…``TrotterQRTE`` (Qiskit#9565)

* added support for t-dep Hamiltonian to algorithms.time_evolvers.trotterization.TrotterQRTE with synthesis LieTrotter

* added support for t-dep Hamiltonians to TrotterQRTE, leaving ProductFormula-classes unchanged wrt main. Also added evaluation of auxiliary_operators at every time-step of TrotterQRTE

* added support for t-dep Hamiltonians to TrotterQRTE, leaving ProductFormula-classes unchanged wrt main. Also added evaluation of auxiliary_operators at every time-step of TrotterQRTE

* removed note that t-dep Hamiltonians are not supported

* modified and added tests for t-dependent Hamiltonians in TrotterQRTE

* added documentation

* adapted code according to PR comments, refined tests to include manual calculation of reference values

* rename new test

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* added inplace argument to assign_parameters._assign_parameters. If False, copies parameter array and returns new bound array leaving the passed array untouched

* fixing ValueErrors in TimeEvolutionProblme and formatting

* added release note

* fix lint suggestions

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
@noure-beep
Copy link

i need i code about trotterization

ElePT pushed a commit to ElePT/qiskit that referenced this pull request Jun 27, 2023
…``TrotterQRTE`` (Qiskit#9565)

* added support for t-dep Hamiltonian to algorithms.time_evolvers.trotterization.TrotterQRTE with synthesis LieTrotter

* added support for t-dep Hamiltonians to TrotterQRTE, leaving ProductFormula-classes unchanged wrt main. Also added evaluation of auxiliary_operators at every time-step of TrotterQRTE

* added support for t-dep Hamiltonians to TrotterQRTE, leaving ProductFormula-classes unchanged wrt main. Also added evaluation of auxiliary_operators at every time-step of TrotterQRTE

* removed note that t-dep Hamiltonians are not supported

* modified and added tests for t-dependent Hamiltonians in TrotterQRTE

* added documentation

* adapted code according to PR comments, refined tests to include manual calculation of reference values

* rename new test

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* added inplace argument to assign_parameters._assign_parameters. If False, copies parameter array and returns new bound array leaving the passed array untouched

* fixing ValueErrors in TimeEvolutionProblme and formatting

* added release note

* fix lint suggestions

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
ElePT pushed a commit to ElePT/qiskit-algorithms-test that referenced this pull request Jul 17, 2023
…``TrotterQRTE`` (Qiskit/qiskit#9565)

* added support for t-dep Hamiltonian to algorithms.time_evolvers.trotterization.TrotterQRTE with synthesis LieTrotter

* added support for t-dep Hamiltonians to TrotterQRTE, leaving ProductFormula-classes unchanged wrt main. Also added evaluation of auxiliary_operators at every time-step of TrotterQRTE

* added support for t-dep Hamiltonians to TrotterQRTE, leaving ProductFormula-classes unchanged wrt main. Also added evaluation of auxiliary_operators at every time-step of TrotterQRTE

* removed note that t-dep Hamiltonians are not supported

* modified and added tests for t-dependent Hamiltonians in TrotterQRTE

* added documentation

* adapted code according to PR comments, refined tests to include manual calculation of reference values

* rename new test

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update qiskit/algorithms/time_evolvers/trotterization/trotter_qrte.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* added inplace argument to assign_parameters._assign_parameters. If False, copies parameter array and returns new bound array leaving the passed array untouched

* fixing ValueErrors in TimeEvolutionProblme and formatting

* added release note

* fix lint suggestions

---------

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: New Feature Include in the "Added" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: algorithms Related to the Algorithms module
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants