# 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.applications.chemistry import (
FermionicOperator,
HamiltonianProblem,
SummedFermionicOperator,
)

hamiltonian = SummedFermionicOperator(
op_list=[
(FermionicOperator(op_list=[("+", 0), ("-", 0)]), 0.2),
(FermionicOperator(op_list=[("-", 1), ("-", 1)]), 0.3),
(FermionicOperator(op_list=[("-", 2), ("-", 2)]), 0.4),
(FermionicOperator(op_list=[("-", 3), ("-", 3)]), 0.5),
(FermionicOperator(op_list=[("+", 0), ("+", 1), ("-", 1), ("-", 0)]), -0.1),
(FermionicOperator(op_list=[("+", 2), ("+", 3), ("-", 2), ("-", 3)]), -0.3),
]
)
hamiltonian_problem = HamiltonianProblem(hamiltonian=hamiltonian, num_particles=[1, 1])

from classiq import Model
from classiq.builtin_functions import HardwareEfficientAnsatz
from classiq.applications.chemistry import GroundStateSolver, GroundStateOptimizer

model = Model()

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

model.HardwareEfficientAnsatz(params=hwea_params)
circuit = model.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.