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

VarQITE sample code fails #9859

Closed
cklee982 opened this issue Mar 27, 2023 · 1 comment · Fixed by #9860
Closed

VarQITE sample code fails #9859

cklee982 opened this issue Mar 27, 2023 · 1 comment · Fixed by #9860
Assignees
Labels
bug Something isn't working mod: algorithms Related to the Algorithms module

Comments

@cklee982
Copy link

Informations

  • Qiskit version: 0.42.1
  • Python version: 3.10.8
  • Operating system: MacOS 12.6, M1 Max chip

What is the current behavior?

VarQITE sample code from https://qiskit.org/documentation/stubs/qiskit.algorithms.time_evolvers.variational.html fails to run, error logs

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [1], line 27
     25 evolution_problem = TimeEvolutionProblem(observable, time)
     26 var_qite = VarQITE(ansatz, var_principle, init_param_values)
---> 27 evolution_result = var_qite.evolve(evolution_problem)

File /opt/homebrew/lib/python3.10/site-packages/qiskit/algorithms/time_evolvers/variational/var_qte.py:143, in VarQTE.evolve(self, evolution_problem)
    135 if evolution_problem.initial_state is not None:
    136     raise ValueError(
    137         "An initial_state was provided to the TimeEvolutionProblem but this is not "
    138         "supported by VarQTE. Please remove this state from the problem definition "
    139         "and set VarQTE.initial_parameters with the corresponding initial parameter "
    140         "values instead."
    141     )
--> 143 init_state_param_dict = self._create_init_state_param_dict(
    144     self.initial_parameters, self.ansatz.parameters
    145 )
    147 # unwrap PauliSumOp (in the future this will be deprecated)
    148 if isinstance(evolution_problem.hamiltonian, PauliSumOp):

File /opt/homebrew/lib/python3.10/site-packages/qiskit/algorithms/time_evolvers/variational/var_qte.py:281, in VarQTE._create_init_state_param_dict(param_values, init_state_parameters)
    279     init_state_parameter_values = param_values
    280 else:
--> 281     raise TypeError(f"Unsupported type of param_values provided: {type(param_values)}.")
    283 init_state_param_dict = dict(zip(init_state_parameters, init_state_parameter_values))
    284 return init_state_param_dict

TypeError: Unsupported type of param_values provided: <class 'qiskit.algorithms.time_evolvers.variational.variational_principles.imaginary_mc_lachlan_principle.ImaginaryMcLachlanPrinciple'>.


Steps to reproduce the problem

Code from https://qiskit.org/documentation/stubs/qiskit.algorithms.time_evolvers.variational.html

import numpy as np

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

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)

What is the expected behavior?

N/A

Suggested solutions

N/A

@cklee982 cklee982 added the bug Something isn't working label Mar 27, 2023
@jakelishman jakelishman transferred this issue from Qiskit/qiskit-metapackage Mar 27, 2023
@jakelishman jakelishman added the mod: algorithms Related to the Algorithms module label Mar 27, 2023
@ElePT
Copy link
Contributor

ElePT commented Mar 28, 2023

Hi @cklee982, thanks for raising this issue. I just opened a PR to fix the outdated code examples #9860.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: algorithms Related to the Algorithms module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants