Skip to content

Second Quantized Hamiltonian

The user can define its chemical problem using second quantized (fermionic) hamiltonian instead of defining the geometry of the molecule. Thus, the user can utilize the power of quantum chemistry software packages such as PYSCF, PSI4 etc., to derive the best suiting hamiltonian for its model.

The user can choose from a vast collection of basis sets, apply complicated symmetries or benefit from existing classical chemical solvers.

Here, we will present a short example of this method using PYSCF. First, using PYSCf a molecule will be converted to fermionic operator. Then, the solving process continues within the standard pipeline.

from classiq.interface.chemistry.molecule import Molecule
from classiq.interface.chemistry.ground_state_problem import MoleculeProblem
from classiq.applications.chemistry.pyscf_hamiltonian import (
    generate_hamiltonian_from_pyscf,
)

molecule = Molecule(
    atoms=[
        ("H", (0.0, 0.0, 0.0)),
        ("H", (0.0, 0.0, 0.735)),
    ],
)
molecule_problem = MoleculeProblem(
    molecule=molecule,
    basis="sto3g",
)

hamiltonian_problem = generate_hamiltonian_from_pyscf(molecule_problem)

from classiq import ModelDesigner
from classiq.builtin_functions import HardwareEfficientAnsatz
from classiq.interface.chemistry.ground_state_solver import GroundStateSolver
from classiq.interface.executor.optimizer_preferences import GroundStateOptimizer

model_designer = ModelDesigner()

NUM_QUBITS = 4
hwea_params = HardwareEfficientAnsatz(
    num_qubits=NUM_QUBITS, connectivity_map=[(0, 1), (1, 2), (2, 3)], reps=3
)

model_designer.HardwareEfficientAnsatz(params=hwea_params)
circuit = model_designer.synthesize()

gs_solver = GroundStateSolver(
    ground_state_problem=hamiltonian_problem,
    ansatz=circuit,
    optimizer_preferences=GroundStateOptimizer(),
)

result = gs_solver.solve()

A basic script to convert MoleculeProblem to HamiltonianProblem using PYSCF is given in classiq.applications.chemistry.pyscf_hamiltonian. The user can extend it, to use more features from PYSCF.

The rest of the solving process is regular.