Qiskit / qiskit-tutorials

A collection of Jupyter notebooks showing how to use the Qiskit SDK
Apache License 2.0
2.28k stars 1.28k forks source link

Add a Variational Quantum Time Evolution Tutorial #1391

Closed ElePT closed 1 year ago

ElePT commented 1 year ago

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 theVarQITE 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 commented 1 year ago

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

woodsp-ibm commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

I'm interested, can I assign to this issue

wenxh0718 commented 1 year ago

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 commented 1 year ago

I'm interested, can I assign to this issue

Yeah you can

ptwnimbe1 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

I am interested in this issue @ElePT

sabinthapa100 commented 1 year ago

I am interested in this issue.

kshitijdave commented 1 year ago

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

woodsp-ibm commented 1 year ago

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 commented 1 year ago

@ElePT Hi , @ichen17 @huckstar and I have submitted a PR https://github.com/Qiskit/qiskit-tutorials/pull/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 commented 1 year ago

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

ElePT commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

huckstar commented 1 year ago

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