Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Add a Variational Quantum Time Evolution Tutorial #1391

Closed
ElePT opened this issue Jan 23, 2023 · 21 comments · Fixed by #1470
Closed

Add a Variational Quantum Time Evolution Tutorial #1391

ElePT opened this issue Jan 23, 2023 · 21 comments · Fixed by #1470
Assignees
Labels
documentation Something is not clear or error in description

Comments

@ElePT
Copy link
Collaborator

ElePT commented Jan 23, 2023

Create a tutorial in qiskit.algorithms to show how to use the new time_evolvers.variational package.

The tutorial should introduce variational quantum imaginary and real time evolution based on McLachlan's variational principle, and show how this can be leveraged using Qiskit classes.

References for VarQTE:

Reference code (extracted from the VarQITE documentation):

from qiskit.algorithms import TimeEvolutionProblem, VarQITE
from qiskit.algorithms.time_evolvers.variational import ImaginaryMcLachlanPrinciple
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import SparsePauliOp
import numpy as np
observable = SparsePauliOp.from_list(
    [
        ("II", 0.2252),
        ("ZZ", 0.5716),
        ("IZ", 0.3435),
        ("ZI", -0.4347),
        ("YY", 0.091),
        ("XX", 0.091),
    ]
)
ansatz = EfficientSU2(observable.num_qubits, reps=1)
init_param_values = np.zeros(len(ansatz.parameters))
for i in range(len(ansatz.parameters)):
    init_param_values[i] = np.pi / 2
var_principle = ImaginaryMcLachlanPrinciple()
time = 1
evolution_problem = TimeEvolutionProblem(observable, time)
var_qite = VarQITE(ansatz, var_principle, init_param_values)
evolution_result = var_qite.evolve(evolution_problem)

As a follow-up, it would also be nice to benchmark the default gradient/qgt methods with the new classically efficient gradients introduced in the qiskit.algorithms.gradients.reverse_gradient package.

These could be set by doing:

from qiskit.algorithms.gradients import ReverseEstimatorGradient, ReverseQGT


var_principle = ImaginaryMcLachlanPrinciple(qgt = ReverseQGT() , gradient = ReverseEstimatorGradient())

Style guidelines:

Here are some references of the style of tutorial we are looking for

Make sure to follow the Qiskit documentation tutorial guidelines: https://qiskit.github.io/qiskit_sphinx_theme/tutorials/tutorials_guidelines.html

More examples for further reference: https://qiskit.github.io/qiskit_sphinx_theme/tutorials/tutorials_examples.html

@ElePT ElePT added the documentation Something is not clear or error in description label Jan 23, 2023
@ElePT
Copy link
Collaborator Author

ElePT commented Jan 23, 2023

@MarcDrudis would you like to be assigned to this issue?

@woodsp-ibm
Copy link
Member

@ElePT For time evolvers we also have the classical time ones and TrotterQRTE (as well as PVQD - a tutorial for this underway). Is there someway to include these algorithms too, something a bit more comprehensive? Maybe a general time evolvers tutorial/section that guides your selection towards one or more of the algorithms - which includes/links to examples then built with these?

@ElePT
Copy link
Collaborator Author

ElePT commented Jan 24, 2023

@woodsp-ibm you're right, we should add a TrotterQRTE tutorial and maybe we could combine it with classical time evolution, and maybe we could just have a generic time evolution tutorial that guides you through all of these. I like the idea.

The reason why I did not open an issue yet is because I wanted to double check with @Cryoris first. He had some refactoring ideas for the current trotter class, and I though that it would probably be more time efficient to not start designing the tutorial until the class is refactored. But I am keeping it in mind.

@ptwnimbe1
Copy link

Variational Quantum Time Evolution:

1.Variational quantum time evolution leverages variational principles to approximate the time evolution of quantum systems. It aims to find the optimal parameters that minimize the discrepancy between the simulated time evolution and the desired target evolution.

  1. Import Required Libraries

  2. Define the Hamiltonian:
    Specify the Hamiltonian of the quantum system you want to simulate. You can represent it using the SparsePauliOp from Qiskit's quantum_info module.

  3. Initialize the Ansatz:
    Create an ansatz, which is a parameterized quantum circuit, using Qiskit's circuit library.

  4. Set Initial Parameter Values:
    Initialize the parameter values of the ansatz. These values will be iteratively updated during the optimization process.

  5. Define the Variational Principle:
    Specify the variational principle to be used. For variational quantum time evolution, you can use ImaginaryMcLachlanPrinciple from Qiskit's qiskit.algorithms.time_evolvers.variational module.

  6. Define the Time Evolution Problem:
    Create a TimeEvolutionProblem object by specifying the Hamiltonian and the desired evolution time.

  7. Run Variational Quantum Time Evolution:
    Create a VarQITE object with the ansatz, variational principle, and initial parameter values. Then, call the evolve method with the time evolution problem.

By following these steps, you can leverage Qiskit's qiskit.algorithms.time_evolvers.variational package to perform variational quantum imaginary and real-time evolution based on McLachlan's variational principle.

By specifying qgt=ReverseQGT() and gradient=ReverseEstimatorGradient() when creating the ImaginaryMcLachlanPrinciple object, you can benchmark the new classically efficient gradients introduced in the qiskit.algorithms.gradients.reverse_gradient package.

  1. Make sure to import the necessary modules for the reverse gradients. This allows you to evaluate and compare the performance of the default gradient/QGT methods with the new classically efficient gradients.

@MihirsinhChauhan
Copy link

I'm interested,
can I assign to this issue

@wenxh0718
Copy link
Contributor

Hi, We are also interested in this issue. Wondering if we can also be considered as a potential assignee for this unitaryHACK? We are planning to submit our first PR next week (by 06/04). Thanks!

@ptwnimbe1
Copy link

I'm interested, can I assign to this issue

Yeah you can

@ptwnimbe1
Copy link

Hi, We are also interested in this issue. Wondering if we can also be considered as a potential assignee for this unitaryHACK? We are planning to submit our first PR next week (by 06/04). Thanks!

Yes, you can. Kindly go ahead

@ElePT
Copy link
Collaborator Author

ElePT commented May 30, 2023

Variational Quantum Time Evolution:

1.Variational quantum time evolution leverages variational principles to approximate the time evolution of quantum systems. It aims to find the optimal parameters that minimize the discrepancy between the simulated time evolution and the desired target evolution.

2. Import Required Libraries

3. Define the Hamiltonian:
   Specify the Hamiltonian of the quantum system you want to simulate. You can represent it using the SparsePauliOp from Qiskit's quantum_info module.

4. Initialize the Ansatz:
   Create an ansatz, which is a parameterized quantum circuit, using Qiskit's circuit library.

5. Set Initial Parameter Values:
   Initialize the parameter values of the ansatz. These values will be iteratively updated during the optimization process.

6. Define the Variational Principle:
   Specify the variational principle to be used. For variational quantum time evolution, you can use ImaginaryMcLachlanPrinciple from Qiskit's qiskit.algorithms.time_evolvers.variational module.

7. Define the Time Evolution Problem:
   Create a TimeEvolutionProblem object by specifying the Hamiltonian and the desired evolution time.

8. Run Variational Quantum Time Evolution:
   Create a VarQITE object with the ansatz, variational principle, and initial parameter values. Then, call the evolve method with the time evolution problem.

By following these steps, you can leverage Qiskit's qiskit.algorithms.time_evolvers.variational package to perform variational quantum imaginary and real-time evolution based on McLachlan's variational principle.

By specifying qgt=ReverseQGT() and gradient=ReverseEstimatorGradient() when creating the ImaginaryMcLachlanPrinciple object, you can benchmark the new classically efficient gradients introduced in the qiskit.algorithms.gradients.reverse_gradient package.

9. Make sure to import the necessary modules for the reverse gradients. This allows you to evaluate and compare the performance of the default gradient/QGT methods with the new classically efficient gradients.

Please take into account that this is not considered a contribution towards the Unitary Hack bounty. The contribution must be made as a PR and follow the content standards and style guidelines specified above.

@ElePT
Copy link
Collaborator Author

ElePT commented May 30, 2023

@MihirsinhChauhan, @wenxh0718 (and others) please note that ptwnimbe1 is not a Qiskit maintainer and cannot assign you to this issue (or tell you to go ahead). You can both go ahead and open a PR making sure you follow the updated style guidelines. You must note that, for the Unitary Hack challenge, we will take into account the quality of the contribution to decide whether it wins the bounty or not, and in principle, there is only one winner.

Once you open the PR, make sure to tag this issue or mention me so I can follow-up on the contribution.

@s-aldaihan
Copy link

I am interested in this issue @ElePT

@sabinthapa100
Copy link

I am interested in this issue.

@kshitijdave
Copy link

I did not understand why doing "evolve" command wrt VarQITE give me error :- TypeError: Unsupported type of param_values provided.

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Jun 3, 2023

I imagine this is the method that is checking it https://github.com/Qiskit/qiskit-terra/blob/332bd9fe0bea82c0fdf7329cea3da115d86e3fc2/qiskit/algorithms/time_evolvers/variational/var_qte.py#L234, maybe that's of help, where param_values seems to relate to initial_parameters passed. You can see the type checks its doing and the failing type should have been part of the error message.

@wenxh0718
Copy link
Contributor

wenxh0718 commented Jun 9, 2023

@ElePT Hi , @ichen17 @huckstar and I have submitted a PR #1470 for this tutorial, please let us know if you have any questions and need any from our side. Thanks and looking forward to your response!

@Raghav-Bell
Copy link

Hey! I have joined Unitary hack 2023 late. Can i contribute to this problem ?

@ElePT
Copy link
Collaborator Author

ElePT commented Jun 13, 2023

Hi @wenxh0718, thanks for your contribution. As this is the only open PR at the moment, I have left you as the only person assigned to the issue. As you have collaborated with @ichen17 and @huckstar, would you like us to distribute the potential bounty among you three (in that case, I need them to comment on the issue so that I can assign them)??

@OuCheng-Fu
Copy link

I have a question about the source code of Quantum Imaginary Evolution. I have tried QAOA with Qiskit QAOA module from the tutorial
https://qiskit.org/documentation/tutorials/algorithms/05_qaoa.html
It has a code
result = qaoa.compute_minimum_eigenvalue(qubit_op)
If I want to compute the minimum eigenvalue of an ising model by QITE, is it possible to use this module?

@wenxh0718
Copy link
Contributor

Hi @wenxh0718, thanks for your contribution. As this is the only open PR at the moment, I have left you as the only person assigned to the issue. As you have collaborated with @ichen17 and @huckstar, would you like us to distribute the potential bounty among you three (in that case, I need them to comment on the issue so that I can assign them)??

Hi @ElePT Yes, that works for us. @ichen17 @huckstar please feel free to comment here. thanks!

@ichen17
Copy link
Contributor

ichen17 commented Jun 14, 2023

Hi, @ElePT Plases assign me to the issue. Thanks.

@huckstar
Copy link
Contributor

Hi @ElePT, please assign me to this issue. Thanks!

ElePT added a commit that referenced this issue Jun 16, 2023
<!--
⚠️ If you do not respect this template, your pull request will be
closed.
⚠️ Your pull request title should be short detailed and understandable
for all.
⚠️ If your pull request fixes an open issue, please link to the issue.

✅ I have added the tests to cover my changes.
✅ I have updated the documentation accordingly.
✅ I have read the CONTRIBUTING document.
-->

### Summary

Unitary Hack submission. Fixes #1391.

### Details and comments
In this tutorial, we
* introduce the variational quantum imaginary and real time evolution
based on McLachlan's variational principle.
* show how this can be leveraged using Qiskit classes.
* benchmark the default gradient/qgt methods with the new classically
efficient gradients introduced in the
qiskit.algorithms.gradients.reverse_gradient package.

This works is done by I-Chi (@ichen17), Kaixin (@huckstar), Wenxiang
(@wenxh0718) collaboratively. Special thanks to FinQ Tech
(http://finq.tech/) for their support and mentorship, which were
instrumental to the successful completion of this quantum computing
hackathon project.

---------

Co-authored-by: ichen17 <66759365+ichen17@users.noreply.github.com>
Co-authored-by: Kaixin <kxhuang@umd.edu>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
ElePT added a commit to ElePT/qiskit-algorithms that referenced this issue Aug 17, 2023
…t-tutorials#1391) (Qiskit/qiskit-tutorials#1470)

<!--
⚠️ If you do not respect this template, your pull request will be
closed.
⚠️ Your pull request title should be short detailed and understandable
for all.
⚠️ If your pull request fixes an open issue, please link to the issue.

✅ I have added the tests to cover my changes.
✅ I have updated the documentation accordingly.
✅ I have read the CONTRIBUTING document.
-->

### Summary

Unitary Hack submission. Fixes Qiskit/qiskit-tutorials#1391.

### Details and comments
In this tutorial, we
* introduce the variational quantum imaginary and real time evolution
based on McLachlan's variational principle.
* show how this can be leveraged using Qiskit classes.
* benchmark the default gradient/qgt methods with the new classically
efficient gradients introduced in the
qiskit.algorithms.gradients.reverse_gradient package.

This works is done by I-Chi (@ichen17), Kaixin (@huckstar), Wenxiang
(@wenxh0718) collaboratively. Special thanks to FinQ Tech
(http://finq.tech/) for their support and mentorship, which were
instrumental to the successful completion of this quantum computing
hackathon project.

---------

Co-authored-by: ichen17 <66759365+ichen17@users.noreply.github.com>
Co-authored-by: Kaixin <kxhuang@umd.edu>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Something is not clear or error in description
Projects
None yet
Development

Successfully merging a pull request may close this issue.