Wavefunction

class slowquant.qiskit_interface.circuit_wavefunction.WaveFunctionCircuit(num_elec: int, cas: Sequence[int], mo_coeffs: ndarray, h_ao: ndarray, g_ao: ndarray, quantum_interface: QuantumInterface, include_active_kappa: bool = False)

Initialize for UCC wave function.

Parameters:
  • num_elec – Number of electrons.

  • cas – CAS(num_active_elec, num_active_orbs), orbitals are counted in spatial basis.

  • mo_coeffs – Initial orbital coefficients.

  • h_ao – One-electron integrals in AO for Hamiltonian.

  • g_ao – Two-electron integrals in AO.

  • quantum_interface – QuantumInterface.

  • include_active_kappa – Include active-active orbital rotations.

_calc_energy_elec() float

Run electronic energy simulation, regardless of self.energy_elec variable.

Returns:

Electronic energy.

_calc_energy_optimization(parameters: list[float], theta_optimization: bool, kappa_optimization: bool) float

Calculate electronic energy.

Parameters:
  • parameters – Ansatz and orbital rotation parameters.

  • theta_optimization – Doing theta optimization.

  • kappa_optimization – Doing kappa optimization.

Returns:

Electronic energy.

_calc_gradient_optimization(parameters: list[float], theta_optimization: bool, kappa_optimization: bool) ndarray

Calculate electronic gradient.

Parameters:
  • parameters – Ansatz and orbital rotation parameters.

  • theta_optimization – Doing theta optimization.

  • kappa_optimization – Doing kappa optimization.

Returns:

Electronic gradient.

_reconstruct_circuit() None

Construct circuit again.

property c_mo: ndarray

Get molecular orbital coefficients.

Returns:

Molecular orbital coefficients.

change_primitive(primitive: BaseEstimator | BaseSamplerV1 | BaseSamplerV2, verbose: bool = True) None

Change the primitive expectation value calculator.

Parameters:
  • primitive – Primitive object.

  • verbose – Print more info.

check_orthonormality(overlap_integral: ndarray) None

Check orthonormality of orbitals.

\[\boldsymbol{I} = \boldsymbol{C}_\text{MO}\boldsymbol{S}\boldsymbol{C}_\text{MO}^T\]
Parameters:

overlap_integral – Overlap integral in AO basis.

property energy_elec: float

Get electronic energy.

Returns:

Electronic energy.

property g_mo: ndarray

Get two-electron Hamiltonian integrals in MO basis.

Returns:

Two-electron Hamiltonian integrals in MO basis.

property h_mo: ndarray

Get one-electron Hamiltonian integrals in MO basis.

Returns:

One-electron Hamiltonian integrals in MO basis.

property kappa: list[float]

Get orbital rotation parameters.

precalc_rdm_paulis(rdm_order: int) None

Pre-calculate all Paulis used to contruct RDMs up to a certain order.

This utilizes the saving feature in QuantumInterface when using the Sampler primitive. If saving is turned up in QuantumInterface this function will do nothing but waste device time.

Parameters:

rdm_order – Max order RDM.

property rdm1: ndarray

Calcuate one-electron reduced density matrix.

The trace condition is enforced:

\[\sum_i\Gamma^{[1]}_{ii} = N_e\]
Returns:

One-electron reduced density matrix.

property rdm2: ndarray

Calcuate two-electron reduced density matrix.

The trace condition is enforced:

\[\sum_{ij}\Gamma^{[2]}_{iijj} = N_e(N_e-1)\]
Returns:

Two-electron reduced density matrix.

property rdm3: ndarray

Calcuate three-electron reduced density matrix.

The trace condition is enforced:

\[\sum_{ijk}\Gamma^{[3]}_{iijjkk} = N_e(N_e-1)(N_e-2)\]
Returns:

Three-electron reduced density matrix.

property rdm4: ndarray

Calcuate four-electron reduced density matrix.

The trace condition is enforced:

\[\sum_{ijkl}\Gamma^{[4]}_{iijjkkll} = N_e(N_e-1)(N_e-2)(N_e-3)\]
Returns:

Four-electron reduced density matrix.

run_wf_optimization_1step(optimizer_name: str, orbital_optimization: bool = False, tol: float = 1e-10, maxiter: int = 1000) None

Run one step optimization of wave function.

Parameters:
  • optimizer_name – Name of optimizer.

  • orbital_optimization – Perform orbital optimization.

  • tol – Convergence tolerance.

  • maxiter – Maximum number of iterations.

run_wf_optimization_2step(optimizer_name: str, orbital_optimization: bool = False, tol: float = 1e-10, maxiter: int = 1000, is_silent_subiterations: bool = False) None

Run two step optimization of wave function.

Parameters:
  • optimizer_name – Name of optimizer.

  • orbital_optimization – Perform orbital optimization.

  • tol – Convergence tolerance.

  • maxiter – Maximum number of iterations.

  • is_silent_subiterations – Silence subiterations.

property thetas: list[float]

Getter for ansatz parameters.

Returns:

Ansatz parameters.

slowquant.qiskit_interface.circuit_wavefunction._get_energy_evals_for_grad(operator: FermionicOperator, quantum_interface: QuantumInterface, parameters: list[float], idx: int, R: int) list[float]

Get energy evaluations needed for the gradient calculation.

The gradient formula is defined for x=0. The x_shift variable is used to shift the energy function, such that current parameter value is in zero.

Parameters:
  • operator – Operator which the derivative is with respect to.

  • parameters – Paramters.

  • idx – Parameter idx.

  • R – Parameter to control we get the needed points.

Returns:

Energies in a few fixed points.