Create an Orbital Optimizer
Goal
Build and configure an orbital optimizer using the fluent builder API. Choose between simple, Newton, and greedy optimizers. Optionally, set estimators, minimizers, gradient calculators, and number of shots for sampling.
Prerequisites
A basic understanding of orbital optimization (rotating molecular orbitals to lower the system’s energy)
Overview
Start the builder with:
import qrunch as qc
opt = qc.orbital_optimizer_creator()
Then narrow to a specific algorithm and call .create():
optimizer = (
qc.orbital_optimizer_creator()
.newton() # or .simple(), .greedy()
# .<configure>(...)
.create()
)
Available Optimizers
A Newton-style optimizer that uses a gradient calculator. Supports finite-difference or local (RDM-based) gradients.
import qrunch as qc
optimizer = (
qc.orbital_optimizer_creator()
.newton()
.choose_gradient_calculator()
.local_gradient( # analytical (RDM-based) gradients
estimator=qc.estimator_creator().excitation_gate().create()
)
.with_shots(None) # None = exact estimator for gradients
.with_options( # optional Newton options
options=qc.options.NewtonMinimizerOptions(...)
)
.create()
)
The Newton-style optimizer with a local gradient calculator is a strong default choice for orbital optimization. It leverages analytical gradients via reduced density matrices (RDMs), leading to efficient and accurate updates.
A lightweight optimizer that uses an estimator and a classical minimizer.
import qrunch as qc
optimizer = (
qc.orbital_optimizer_creator()
.simple()
.with_estimator( # optional: set custom estimator
estimator=qc.estimator_creator().excitation_gate().create()
)
.choose_minimizer() # optional: choose custom minimizer
.scipy(
name="L-BFGS-B",
options=qc.options.ScipyMinimizerOptions(...)
)
.with_shots(None) # None = exact estimator; or an int for finite shots
.create()
)
A greedy strategy using a minimizer over greedily-selected orbital rotations.
import qrunch as qc
optimizer = (
qc.orbital_optimizer_creator()
.greedy()
.with_estimator( # optional: custom estimator
estimator=qc.estimator_creator().excitation_gate().create()
)
.choose_minimizer() # optional: custom minimizer
.scipy(name="Powell", options=qc.options.ScipyMinimizerOptions(...))
.with_shots(None)
.create()
)
Next Step
Use the orbital optimizer within VQE calculator variants that support orbital rotations (e.g., OO-BEAST, OO-FAST-VQE).