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

Transpile for VQE application #6432

Closed
hhorii opened this issue May 18, 2021 · 1 comment
Closed

Transpile for VQE application #6432

hhorii opened this issue May 18, 2021 · 1 comment
Labels
mod: algorithms Related to the Algorithms module mod: opflow Related to the Opflow module type: enhancement It's working, but needs polishing

Comments

@hhorii
Copy link
Contributor

hhorii commented May 18, 2021

What is the expected enhancement?

Currently, if a number of pauli-lists for expectation value is N, qiskit transpiles N circuits though their prefix are the same. This is because operator-flow generates circuits before transpilation.

A possible solution will be that operator-flow transpiles a circuit and then combines pauli-lists. This solution will still remain deepcopy issue to generate multi-circuits.

Another solution will be that provider supports snapshot operations such as Aer-provider does.

qiskit-terra f104bbf: first 12 minutes, include_custom=False
image

import sys
import numpy as np
import multiprocessing
from time import time

from qiskit_nature.transformers import FreezeCoreTransformer

mol_strings = {
            'H2': 'H .0 .0 .0; H .0 .0 0.735',
            'LiH': 'H .0 .0 .0; Li .0 .0 2.5',
            'HF': 'H .0 .0 .0; F .0 .0 1.25',
}

mol_string = mol_strings['LiH']
#mol_string = mol_strings['H2']
method = 'qasm_simulator'
#method = 'statevector_simulator'
threads = 32

from qiskit_nature.drivers import PySCFDriver, UnitsType
driver = PySCFDriver(atom=mol_string, unit=UnitsType.ANGSTROM, basis="sto3g")

from qiskit_nature.problems.second_quantization import ElectronicStructureProblem
problem = ElectronicStructureProblem(driver)

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

# from qiskit.algorithms.optimizers import L_BFGS_B
# optimizer = L_BFGS_B()

from qiskit.algorithms.optimizers import SLSQP
optimizer = SLSQP(maxiter=5000)

from qiskit_nature.mappers.second_quantization import ParityMapper
from qiskit_nature.converters.second_quantization import QubitConverter

converter = QubitConverter(mapper=ParityMapper(), two_qubit_reduction=False)

qubit_op = converter.convert(main_op, num_particles=num_particles)

from qiskit_nature.circuit.library import HartreeFock

init_state = HartreeFock(num_spin_orbitals, num_particles, converter)

from qiskit_nature.circuit.library import UCCSD
#from qiskit_nature.circuit.library import SUCCD

ansatz = UCCSD(
    converter,
    num_particles,
    num_spin_orbitals,
    initial_state=init_state,
)

# set the backend for the quantum computation
from qiskit.utils import QuantumInstance
from qiskit_nature.algorithms import VQEUCCFactory
from qiskit import Aer

backend = Aer.get_backend(method)
quantum_instance = QuantumInstance(backend = backend)
quantum_instance.backend_options['backend_options'] = {'max_parallel_experiments':threads} 

vqe_solver = VQEUCCFactory(quantum_instance, optimizer=optimizer, include_custom=False, ansatz=ansatz, initial_state=init_state)
vqe_solver._vqe._max_evals_grouped = 128
optimizer.set_max_evals_grouped(vqe_solver._vqe._max_evals_grouped)

from qiskit_nature.algorithms import GroundStateEigensolver
calc = GroundStateEigensolver(converter, vqe_solver)
res = calc.solve(problem)

print(res)

When we set include_custom=True, this program finishes within few minutes.

image

@hhorii hhorii added the type: enhancement It's working, but needs polishing label May 18, 2021
@woodsp-ibm woodsp-ibm added mod: algorithms Related to the Algorithms module mod: opflow Related to the Opflow module labels May 18, 2021
@hhorii
Copy link
Contributor Author

hhorii commented Jun 23, 2022

Primitive will resolve this issue.

@hhorii hhorii closed this as completed Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: algorithms Related to the Algorithms module mod: opflow Related to the Opflow module type: enhancement It's working, but needs polishing
Projects
None yet
Development

No branches or pull requests

2 participants