Skip to content

VarQITE sample code fails #9859

@cklee982

Description

@cklee982

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingmod: algorithmsRelated to the Algorithms module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions