qiskit-community / qiskit-nature

Qiskit Nature is an open-source, quantum computing, framework for solving quantum mechanical natural science problems.
https://qiskit-community.github.io/qiskit-nature/
Apache License 2.0
300 stars 203 forks source link

Two Qubit Reduction sample with UCCSD fails with missing Z2_symmetries argument #153

Closed woodsp-ibm closed 3 years ago

woodsp-ibm commented 3 years ago

The following error results when running the code sample that follows. Run with two_qubit_reduction=False on the convertor and it works fine. I think the problem is more likely in the code in Terra, but since most of the sample is nature I raised it here but it can be transferred to Terra if it indeed turns out to be where the problem needs fixing.

  File "qiskit_nature/circuit/library/ansatzes/evolved_operator_ansatz.py", line 165, in <listcomp>
    evolved_ops = [self.evolution.convert((coeff * op).exp_i()) for op in self.operators]
  File "qiskit/opflow/operator_base.py", line 355, in __rmul__
    return self.mul(other)
  File "qiskit/opflow/primitive_ops/pauli_sum_op.py", line 130, in mul
    return super().mul(scalar)
  File "qiskit/opflow/primitive_ops/primitive_op.py", line 138, in mul
    return self.__class__(self.primitive, coeff=self.coeff * scalar)
TypeError: __init__() missing 1 required positional argument: 'z2_symmetries'

Here is the code sample to reproduce the above:

from qiskit_nature.drivers import PySCFDriver, UnitsType
from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem
# Use PySCF, a classical computational chemistry software
# package, to compute the one-body and two-body integrals in
# electronic-orbital basis, necessary to form the Fermionic operator
driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.735',
                     unit=UnitsType.ANGSTROM,
                     basis='sto3g')
problem = ElectronicStructureProblem(driver)
# generate the second-quantized operators
second_q_ops = problem.second_q_ops()
main_op = second_q_ops[0]
num_particles = (problem.molecule_data_transformed.num_alpha,
                 problem.molecule_data_transformed.num_beta)
num_spin_orbitals = 2 * problem.molecule_data.num_molecular_orbitals
# setup the classical optimizer for VQE
from qiskit.algorithms.optimizers import L_BFGS_B
optimizer = L_BFGS_B()
# setup the mapper and qubit converter
from qiskit_nature.mappers.second_quantization import ParityMapper
from qiskit_nature.converters.second_quantization import QubitConverter
mapper = ParityMapper()
converter = QubitConverter(mapper=mapper, two_qubit_reduction=True)
# map to qubit operators
qubit_op = converter.convert(main_op, num_particles=num_particles)
# setup the initial state for the ansatz
from qiskit_nature.circuit.library import HartreeFock
init_state = HartreeFock(num_spin_orbitals, num_particles, converter)
# setup the ansatz for VQE
from qiskit_nature.circuit.library import UCCSD
ansatz = UCCSD(converter,num_particles,num_spin_orbitals,1,init_state)
from qiskit import Aer
backend = Aer.get_backend('statevector_simulator')
# setup and run VQE
from qiskit.algorithms import VQE
algorithm = VQE(ansatz,
                optimizer=optimizer,
                quantum_instance=backend)
result = algorithm.compute_minimum_eigenvalue(qubit_op)
print(result.eigenvalue.real)

The issue was originally raised on the external Slack channel: https://qiskit.slack.com/archives/CB6C24TPB/p1619192806297800

mrossinek commented 3 years ago

Seems to be a duplicate of this issue: https://github.com/Qiskit/qiskit-terra/issues/6127

mrossinek commented 3 years ago

Once https://github.com/Qiskit/qiskit-terra/pull/6315 is merged we need to remove this line in order to close this issue. While validating the fix of the PR in Terra I noticed that we can probably also remove the @slow_test decorators because these tests aren't actually that slow..

mrossinek commented 3 years ago

Closed by Qiskit/qiskit-terra#6315