question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`BOPESSampler` does not support `MinimumEigensolverFactories`

See original GitHub issue

Information

  • Qiskit Nature version: cb05d69661a9d467aed9d3f208ea5630f7dc9fbf
  • Python version: 3.9.7
  • Operating system: Linux

What is the current behavior?

Traceback (most recent call last):
  File "/home/oss/Files/Qiskit/src/qiskit-nature/main/tmp10.py", line 32, in <module>
    bs = BOPESSampler(VQEUCCFactory)
  File "/home/oss/Files/Qiskit/src/qiskit-nature/main/qiskit_nature/algorithms/pes_samplers/bopes_sampler.py", line 95, in __init__
    if isinstance(self._gss.solver, VariationalAlgorithm):  # type: ignore
AttributeError: type object 'VQEUCCFactory' has no attribute 'solver'

Steps to reproduce the problem

from functools import partial

import numpy as np

from qiskit_nature.algorithms.ground_state_solvers.minimum_eigensolver_factories import (
    VQEUCCFactory,
)
from qiskit_nature.algorithms.pes_samplers import BOPESSampler
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.drivers import Molecule
from qiskit_nature.drivers.second_quantization import (
    ElectronicStructureDriverType,
    ElectronicStructureMoleculeDriver,
)
from qiskit_nature.mappers.second_quantization import ParityMapper
from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem

stretch = partial(Molecule.absolute_distance, atom_pair=(0, 1))

molecule = Molecule(
    geometry=[
        ["H", [0.0, 0.0, 0.0]],
        ["H", [0.0, 0.0, 1.0]],
    ],
    degrees_of_freedom=[stretch],
)
driver = ElectronicStructureMoleculeDriver(molecule, "sto3g", ElectronicStructureDriverType.PYSCF)
problem = ElectronicStructureProblem(driver)

converter = QubitConverter(ParityMapper())

bs = BOPESSampler(VQEUCCFactory)

res = bs.sample(problem, np.linspace(0.5, 3.0, 20))
print(res)

What is the expected behavior?

The BOPESSampler should support MininmumEigensolverFactory classes.

Suggested solutions

Add a check similar to the one in the GroundStateEigensolver: https://github.com/Qiskit/qiskit-nature/blob/main/qiskit_nature/algorithms/ground_state_solvers/ground_state_eigensolver.py#L103-L105

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
iuliazidarucommented, Jan 14, 2022

@mrossinek Yes, I’ll check this next week. It makes more sense. There was an issue with this approach, but I don’t remember it right now. It’s about the second quantisation/ solver creation and the problem which is provided only when solve method is called. I’ll keep you updated.

0reactions
mrossinekcommented, Jan 14, 2022

I’ve had an offline discussion with @woodsp-ibm regarding PR #457. The question arose whether we really want to support a syntax like the one proposed there: gss: Union[GroundStateSolver, MinimumEigensolverFactory] + require a QubitConverter in the latter case… Or whether instead we should stick to the (arguably more obvious) solution of doing:

BopesSampler(
    GroundStateEigensolver(
        some_qubit_converter,
        VQEUCCFactory(some_quantum_instance),
    )
)

I.e. instead of adding support for the factory directly inside of the BopesSampler, we should instead make sure that it knows how to handle a GSS which was initialized with a factory.

Unfortunately the code snippet in my original description of this issue at the top here is not valid (I don’t quite know how that happened), but this latter case is still flawed as it does not work as intended today either. Here is a new snippet:

from functools import partial

import numpy as np

from qiskit.providers.aer import StatevectorSimulator
from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver
from qiskit_nature.algorithms.ground_state_solvers.minimum_eigensolver_factories import (
    VQEUCCFactory,
)
from qiskit_nature.algorithms.pes_samplers import BOPESSampler
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.drivers import Molecule
from qiskit_nature.drivers.second_quantization import (
    ElectronicStructureDriverType,
    ElectronicStructureMoleculeDriver,
)
from qiskit_nature.mappers.second_quantization import ParityMapper
from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem

stretch = partial(Molecule.absolute_distance, atom_pair=(0, 1))

molecule = Molecule(
    geometry=[
        ["H", [0.0, 0.0, 0.0]],
        ["H", [0.0, 0.0, 1.0]],
    ],
    degrees_of_freedom=[stretch],
)
driver = ElectronicStructureMoleculeDriver(molecule, "sto3g", driver_type=ElectronicStructureDriverType.PYSCF)
problem = ElectronicStructureProblem(driver)

converter = QubitConverter(ParityMapper())

solver = GroundStateEigensolver(converter, VQEUCCFactory(StatevectorSimulator()))

bs = BOPESSampler(solver)

res = bs.sample(problem, np.linspace(0.5, 3.0, 2))
print(res.point_results)

It produces the following error when using the latest main installations of Qiskit Nature and Terra:

Traceback (most recent call last):
  File "/home/oss/Files/Qiskit/src/qiskit-nature/main/tmp2.py", line 38, in <m
    res = bs.sample(problem, np.linspace(0.5, 3.0, 2))
  File "/home/oss/Files/Qiskit/src/qiskit-nature/main/qiskit_nature/algorithms
    self._raw_results = self._run_points(points)
  File "/home/oss/Files/Qiskit/src/qiskit-nature/main/qiskit_nature/algorithms
    raw_result = self._run_single_point(point)  # dict of results
  File "/home/oss/Files/Qiskit/src/qiskit-nature/main/qiskit_nature/algorithms
    self._points_optparams[point] = optimal_params
TypeError: 'NoneType' object does not support item assignment

I believe if we try to fix that error instead, we do not need the proposal of #457 as it is potentially too convoluted.

@iuliazidaru I am sorry that you have already put so much work into that PR. Would you still be interested in attempting this new approach, instead? 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

qiskit-nature/ground_state_eigensolver.py at main - GitHub
according to a mapper it is initialized with. solver: Minimum Eigensolver or MESFactory object, e.g. the VQEUCCSDFactory.
Read more >
One Size Doesn't Fit All: Using Factor Analysis to Gather ...
In our study, the total sample size was 796 students. Considering the number of factors (two) and the relatively large number of items...
Read more >
Code Examples - oj! Algorithms
All code examples regardless of where or when they were published can be found here (further down on this page). The individual code...
Read more >
Exploratory Factor Analysis: A Guide to Best Practice
An eigenvalue is computed for each of the resulting factors to indicate the amount of variance accounted for by that factor independent of...
Read more >
Msbte Sample Question Paper 2nd Sem G Scheme Mechanical
scheme mechanical that we will categorically offer. It is not not far off from the costs. Its virtually what you craving currently.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found