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

scf issue #1373

Open
deepankarpal1985 opened this issue Jan 2, 2025 · 0 comments
Open

scf issue #1373

deepankarpal1985 opened this issue Jan 2, 2025 · 0 comments
Labels

Comments

@deepankarpal1985
Copy link

Environment

  • 0.7.2:
  • 3.11:
  • Ansys Lab:

What is happening?


MissingOptionalLibraryError Traceback (most recent call last)
Cell In[97], line 3
1 # Step 2: Simulate energies for a range of strains
2 strain_values = np.linspace(-0.1, 0.1, 5) # Strain range from -10% to +10%
----> 3 energies = [simulate_strain(strain) for strain in strain_values]

Cell In[97], line 3, in (.0)
1 # Step 2: Simulate energies for a range of strains
2 strain_values = np.linspace(-0.1, 0.1, 5) # Strain range from -10% to +10%
----> 3 energies = [simulate_strain(strain) for strain in strain_values]

Cell In[96], line 4, in simulate_strain(atom_displacement)
2 def simulate_strain(atom_displacement):
3 # 1a. Define molecular structure under strain
----> 4 driver = PySCFDriver(
5 atom=f"H 0.0 0.0 0.0; H 0.0 0.0 {0.74 +atom_displacement}",
6 unit=DistanceUnit.ANGSTROM,
7 basis="sto3g"
8 )
9 # 1b. Generate the electronic structure problem
10 problem = driver.run()

File /opt/conda/lib/python3.11/site-packages/qiskit/utils/classtools.py:111, in _WrappedMethod.get..out(*args, **kwargs)
108 @functools.wraps(method)
109 def out(*args, **kwargs):
110 for callback in self._before:
--> 111 callback.get(obj, objtype)(*args, **kwargs)
112 retval = method(*args, **kwargs)
113 for callback in self._after:

File /opt/conda/lib/python3.11/site-packages/qiskit/utils/lazy_tester.py:41, in _RequireNow.call(self, *_args, **_kwargs)
40 def call(self, *_args, **_kwargs):
---> 41 self._tester.require_now(self._feature)

File /opt/conda/lib/python3.11/site-packages/qiskit/utils/lazy_tester.py:221, in LazyDependencyManager.require_now(self, feature)
219 if self:
220 return
--> 221 raise MissingOptionalLibraryError(
222 libname=self._name, name=feature, pip_install=self._install, msg=self._msg
223 )

MissingOptionalLibraryError: "The 'pyscf' library is required to use 'PySCFDriver'. See https://pyscf.org/install.html."

How can we reproduce the issue?

Importing necessary libraries

import numpy as np
import matplotlib.pyplot as plt
import pyscf

Qiskit imports

from qiskit_aer.primitives import Estimator # <-- for Aer-based estimation
from qiskit_algorithms.minimum_eigensolvers import VQE
from qiskit_algorithms.optimizers import COBYLA
from qiskit.circuit.library import EfficientSU2

Qiskit Nature imports

from qiskit_nature.second_q.drivers import PySCFDriver
from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.problems import ElectronicStructureProblem
from qiskit_nature.second_q.mappers import JordanWignerMapper
from qiskit_nature.second_q.algorithms import GroundStateEigensolver

Step 1: Function to compute energy for different strains

def simulate_strain(atom_displacement):
# 1a. Define molecular structure under strain
driver = PySCFDriver(
atom=f"H 0.0 0.0 0.0; H 0.0 0.0 {0.74 +atom_displacement}",
unit=DistanceUnit.ANGSTROM,
basis="sto3g"
)
# 1b. Generate the electronic structure problem
problem = driver.run()

# 1c. Map the electronic problem to a qubit operator
mapper = JordanWignerMapper()
# This will give you a list of second-quantized operators; the first one is usually the Hamiltonian
second_q_op = problem.second_q_ops()[0]

# 1d. Create an Estimator for the Aer simulator
#     You can pass backend options here, e.g. 'method': 'statevector'
estimator = Estimator(
    backend=Aer.get_backend("aer_simulator_statevector"),
    backend_options={"method": "statevector"}
)

# 1e. Define the ansatz and optimizer for VQE
ansatz = EfficientSU2(num_qubits=problem.num_spin_orbitals, reps=2, entanglement="full")
optimizer = COBYLA(maxiter=100)

# 1f. Create the VQE solver using the Aer-based Estimator
vqe = VQE(estimator=estimator, ansatz=ansatz, optimizer=optimizer)

# 1g. Use GroundStateEigensolver to compute the ground-state energy
gsc = GroundStateEigensolver(mapper, vqe)
result = gsc.solve(problem)

# Return the total (ground-state) energy
return result.total_energies[0]

Step 2: Simulate energies for a range of strains

strain_values = np.linspace(-0.1, 0.1, 5) # Strain range from -10% to +10%
energies = [simulate_strain(strain) for strain in strain_values]

What should happen?

For the atom displacements for linear strain, it should run the definition of strain

Any suggestions?

I am not aware of this scf issue-I am a new user-so I need help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant