Wavefunction

class slowquant.qiskit_interface.wavefunction.WaveFunction(num_spin_orbs: int, num_elec: int, cas: Sequence[int], c_orthonormal: ndarray, h_ao: ndarray, g_ao: ndarray, quantum_interface: QuantumInterface, include_active_kappa: bool = False)

Initialize for UCC wave function.

Parameters:
  • num_spin_orbs – Number of spin orbitals.

  • num_elec – Number of electrons.

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

  • c_orthonormal – 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.

_get_hamiltonian() FermionicOperator

Return electronic Hamiltonian as FermionicOperator.

Returns:

FermionicOperator.

property ansatz_parameters: list[float]

Getter for ansatz parameters.

Returns:

Ansatz parameters.

property c_orthonormal: ndarray

Get orthonormalization coefficients (MO coefficients).

Returns:

Orthonormalization coefficients.

property c_trans: ndarray

Get orbital coefficients.

Returns:

Orbital coefficients.

change_primitive(primitive: BaseEstimatorV1 | BaseSamplerV1) None

Change the primitive expectation value calculator.

Parameters:

primitive – Primitive object.

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 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.

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

Run VQE of wave function.

run_vqe_2step(ansatz_optimizer: str, orbital_optimization: bool = False, tol: float = 1e-08, maxiter: int = 1000, is_silent_subiterations: bool = False) None

Run VQE of wave function.

slowquant.qiskit_interface.wavefunction.ansatz_parameters_gradient(parameters: list[float], operator: FermionicOperator, quantum_interface: QuantumInterface) ndarray

Calculate gradient with respect to ansatz parameters.

Parameters:
  • parameters – Ansatz parameters.

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

  • quantum_interface – Interface to call quantum device.

Returns:

Gradient with repsect to ansatz parameters.

slowquant.qiskit_interface.wavefunction.calc_energy_both(parameters, wf) float

Calculate electronic energy.

Parameters:
  • parameters – Ansatz and orbital rotation parameters.

  • wf – Wave function object.

Returns:

Electronic energy.

slowquant.qiskit_interface.wavefunction.calc_energy_oo(kappa: list[float], wf: WaveFunction) float

Calculate electronic energy using RDMs.

Parameters:
  • kappa – Orbital rotation parameters.

  • wf – Wave function object.

Returns:

Electronic energy.

slowquant.qiskit_interface.wavefunction.calc_energy_theta(parameters: list[float], operator: FermionicOperator, quantum_interface: QuantumInterface) float

Calculate electronic energy using expectation values.

Parameters:
  • paramters – Ansatz paramters.

  • operator – Hamiltonian operator.

  • quantum_interface – QuantumInterface.

Returns:

Electronic energy.

slowquant.qiskit_interface.wavefunction.calc_gradient_both(parameters: list[float], wf: WaveFunction) ndarray

Calculate electronic gradient.

Parameters:
  • parameters – Ansatz and orbital rotation parameters.

  • wf – Wave function object.

Returns:

Electronic gradient.

slowquant.qiskit_interface.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, so x_shift is used to shift ensure we can get the energy in the point we actually want.

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.

slowquant.qiskit_interface.wavefunction.orbital_rotation_gradient(placeholder, wf) ndarray

Calcuate electronic gradient with respect to orbital rotations.

Parameters:
  • placeholder – Placeholder for kappa parameters, these are fetched OOP style instead.

  • wf – Wave function object.

Returns:

Electronic gradient with respect to orbital rotations.