Quantum Chemistry
Submodules
chemistry tools module
- class tequila_code.quantumchemistry.chemistry_tools.ActiveSpaceData(active_orbitals: list = None, reference_orbitals: list = None)[source]
Bases:
object
Small dataclass to keep the overview in active spaces Class is used internally
- active_orbitals: list = None
- property active_reference_orbitals
- property frozen_reference_orbitals
- reference_orbitals: list = None
- class tequila_code.quantumchemistry.chemistry_tools.Amplitudes(tIjAb: ndarray = None, tIA: ndarray = None, tiJaB: ndarray = None, tijab: ndarray = None, tIJAB: ndarray = None, tia: ndarray = None)[source]
Bases:
object
Helper class for classical Coupled-Cluster Amplitudes We adopt the Psi4 notation for consistency I,A for alpha i,a for beta
- classmethod from_closed_shell(cs: ClosedShellAmplitudes)[source]
Initialize from closed-shell Amplitude structure
- Parameters:
cs (ClosedShellAmplitudes :)
- make_parameter_dictionary(threshold=1e-08)[source]
- Parameters:
threshold – (Default value = 1.e-8) Neglect amplitudes below the threshold
- Return type:
Dictionary of tequila variables (hash is in the style of (a,i,b,j))
- tIA: ndarray = None
- tIJAB: ndarray = None
- tIjAb: ndarray = None
- tiJaB: ndarray = None
- tia: ndarray = None
- tijab: ndarray = None
- class tequila_code.quantumchemistry.chemistry_tools.ClosedShellAmplitudes(tIjAb: ndarray = None, tIA: ndarray = None)[source]
Bases:
object
Helper Class for clasical amplitudes used internally
- make_parameter_dictionary(threshold=1e-08, screening=True)[source]
- Parameters:
threshold – (Default value = 1.e-8)
- tIA: ndarray = None
- tIjAb: ndarray = None
- class tequila_code.quantumchemistry.chemistry_tools.FermionicGateImpl(generator, p0, transformation, indices=None, *args, **kwargs)[source]
Bases:
QubitExcitationImpl
Small helper class for Fermionic Excictation Gates Mainly so that “FermionicGate is displayed when circuits are printed
- cCRy(target: int, dcontrol: list | int, control: list | int, angle: Real | Variable | Hashable, case: int = 1) QCircuit [source]
Compilation of CRy as on https://doi.org/10.1103/PhysRevA.102.062612 If not control passed, Ry returned :param case: :type case: if 1 employs eq. 12 from the paper, if 0 eq. 13
- fermionic_excitation(angle: Real | Variable | Hashable, indices: List, control: int | List = None, opt: bool = True) QCircuit [source]
Excitation [(i,j),(k,l)],… compiled following https://doi.org/10.1103/PhysRevA.102.062612 opt: whether to optimized CNOT H CNOT –> Rz Rz CNOT Rz
- format_excitation_indices(idx)[source]
Consistent formatting of excitation indices idx = [(p0,q0),(p1,q1),…,(pn,qn)] sorted as: p0<p1<pn and pi<qi :param idx: list of index tuples describing a single(!) fermionic excitation :return: list of index tuples
- format_excitation_variables(idx)[source]
Consistent formatting of excitation variable idx = [(p0,q0),(p1,q1),…,(pn,qn)] sorted as: pi<qi and p0 < p1 < p2 :param idx: list of index tuples describing a single(!) fermionic excitation :return: sign of the variable with re-ordered indices
- is_convertable_to_qubit_excitation()[source]
spin-paired double excitations (both electrons occupy the same spatial orbital and are excited to another spatial orbital) in the jordan-wigner representation are identical to 4-qubit excitations which can be compiled more efficient this function hels to automatically detect those cases
- class tequila_code.quantumchemistry.chemistry_tools.IntegralManager(one_body_integrals, two_body_integrals, basis_name='unknown', orbital_type='unknown', constant_term=0.0, orbital_coefficients=None, active_space=None, overlap_integrals=None, orbitals=None, *args, **kwargs)[source]
Bases:
object
Manage Basis Integrals of Quantum Chemistry All integrals are held in their original basis, the corresponding mo-coefficients have to be passed down and are usually held by the QuantumChemistryBaseClass
- property active_orbitals
- property active_reference_orbitals
- property active_space
- property constant_term
rtype: return constant term (usually nuclear repulsion). No active space considered
- get_integrals(orbital_coefficients=None, ordering='openfermion', ignore_active_space=False, *args, **kwargs)[source]
Get all molecular integrals in given orbital basis (determined by orbital_coefficients in self or the ones passed here) active space is considered if not explicitly ignored :param orbital_coefficients: :type orbital_coefficients: orbital coefficients in the given basis (first index is basis, second index is orbitals). Need to go over full basis (no active space) :param ordering: :type ordering: ordering of the two-body integrals (default is openfermion) :param ignore_active_space: :type ignore_active_space: ignore active space and give back full integrals
- get_orthonormalized_orbital_coefficients()[source]
Computes orbitals in this basis that are orthonormal (through loewdin orthonormalization)
- Return type:
coefficient matrix of orthonormalized orbitals
- property one_body_integrals
rtype: one_body integrals in given basis (using basis functions, not molecular orbitals. No active space considered)
- property orbital_coefficients
second index is the orbital index, first the basis index :rtype: orbital coefficient matrix C_{basis,orbital}
- property orbitals
- property overlap_integrals
rtype: Overlap integrals in given basis (using basis functions, not molecular orbitals. No active space considered)
- property reference_orbitals
- transform_orbitals(U, name=None)[source]
Transform orbitals :param U: :type U: second index is new orbital indes, first is old orbital index (summed over)
- Returns:
updates the structure with new orbitals
- Return type:
c = cU
- transform_to_native_orbitals()[source]
Transform orbitals to orthonormal functions closest to the native basis
- property two_body_integrals
returns: * two-body orbitals in given basis (using basis functions, not molecular orbitals. No active space considered) * ordering is “chem” i.e. Mulliken i.e. integrals_{abcd} = <ac|g|bd>
- verify_orbital_coefficients(orbital_coefficients, tolerance=1e-05)[source]
Verify if orbital coefficients are valid (i.e. if they define a orthonormal set of orbitals) :param orbital_coefficients: :type orbital_coefficients: the orbital coefficients C_ij with i:basis and j:orbitals :param tolerance:
- Return type:
True or False depending if the overlap matrix of the basis is transformed to a unit matrix
- class tequila_code.quantumchemistry.chemistry_tools.NBodyTensor(elems: ndarray = None, active_indices: list = None, ordering: str = None, size_full: int = None, verify=False)[source]
Bases:
object
Convenience class for handling N-body tensors
- class Ordering(scheme)[source]
Bases:
object
Convenience to keep track of aliases in odering names for two body integrals i.e. Mulliken/Chem/1122
Dirac/Phys/1212 openfermion/1221
- reorder(to: str = 'of')[source]
Function to reorder tensors according to some convention.
- Parameters:
to –
Ordering scheme of choice. ‘openfermion’, ‘of’ (default) :
openfermion - ordering, corresponds to integrals of the type h^pq_rs = int p(1)* q(2)* O(1,2) r(2) s(1) (O(1,2) with operators a^pq_rs = a^p a^q a_r a_s (a^p == a^dagger_p) currently needed for dependencies on openfermion-library
- ’chem’, ‘c’ :
quantum chemistry ordering, collect particle terms, more convenient for real-space methods h^pq_rs = int p(1) q(1) O(1,2) r(2) s(2) This is output by psi4
- ’phys’, ‘p’ :
typical physics ordering, integrals of type h^pq_rs = int p(1)* q(2)* O(1,2) r(1) s(2) with operators a^pq_rs = a^p a^q a_s a_r
- property shape
- sub_lists(idx_lists: list = None) ndarray [source]
Get subspace of tensor by a set of index lists according to hPQ.sub_lists(idx_lists=[p, q]) = [hPQ for P in p and Q in q]
This essentially is an implementation of a non-contiguous slicing using numpy.take
- Parameters:
idx_lists – List of lists, each defining the desired subspace per axis Size needs to match order of tensor, and lists successively correspond to axis=0,1,2,…,N
- Returns:
Sliced tensor as numpy.ndarray
- Return type:
out
- sub_str(name: str) ndarray [source]
Get subspace of tensor by a string Currently is able to resolve an active space, named ‘a’, full space ‘f’, and the complement ‘p’ = ‘f’ - ‘a’. Full space in this context may also be smaller than actual tensor dimension.
The specification of active space in this context only allows to pick a set from a list of orbitals, and is not able to resolve an active space from irreducible representations.
Example for one-body tensor: hPQ.sub_lists(name=’ap’) = [hPQ for P in active_indices and Q in _passive_indices]
- Parameters:
name – String specifying the desired subspace, elements need to be a (active), f (full), p (full - active)
- Returns:
Sliced tensor as numpy.ndarray
- Return type:
out
- class tequila_code.quantumchemistry.chemistry_tools.OrbitalData(irrep: str = None, idx_irrep: int = None, idx_total: int = None, idx: int = None, energy: float = None, occ: float = None, pair: tuple = None)[source]
Bases:
object
- energy: float = None
- idx: int = None
- idx_irrep: int = None
- idx_total: int = None
- irrep: str = None
- occ: float = None
- pair: tuple = None
- class tequila_code.quantumchemistry.chemistry_tools.ParametersQC(basis_set: str = None, geometry: str = None, description: str = '', multiplicity: int = 1, charge: int = 0, name: str = None, frozen_core: bool = True)[source]
Bases:
object
Specialization of ParametersHamiltonian
- basis_set: str = None
- charge: int = 0
- static convert_to_list(geometry)[source]
Convert a molecular structure given as a string into a list suitable for openfermion
- geometry :
a string specifying a mol. structure. E.g. geometry=”h 0.0 0.0 0.0
h 0.0 0.0 1.0”
- type
A list with the correct format for openfermion E.g return [ [‘h’,[0.0,0.0,0.0], [..]]
- description: str = ''
- property filename
- static format_element_name(string)[source]
OpenFermion uses case sensitive hash tables for chemical elements I.e. you need to name Lithium: ‘Li’ and ‘li’ or ‘LI’ will not work this convenience function does the naming :return: first letter converted to upper rest to lower
- Parameters:
string
- frozen_core: bool = True
- geometry: str = None
- get_geometry()[source]
Returns the geometry If a xyz filename was given the file is read out otherwise it is assumed that the geometry was given as string which is then reformatted as a list usable as input for openfermion :return: geometry as list e.g. [(h,(0.0,0.0,0.35)),(h,(0.0,0.0,-0.35))] Units: Angstrom!
- property molecular_data_param: dict
Give back all parameters for the MolecularData format from openfermion as dictionary
- Type:
return
- multiplicity: int = 1
- property n_electrons
- name: str = None
- static read_xyz_from_file(filename)[source]
Read XYZ filetype for molecular structures https://en.wikipedia.org/wiki/XYZ_file_format Units: Angstrom!
- Parameters:
filename – return:
encodings module
Collections of Fermion-to-Qubit encodings known to tequila Most are Interfaces to OpenFermion
- class tequila_code.quantumchemistry.encodings.BravyiKitaev(n_electrons, n_orbitals, up_then_down=False, *args, **kwargs)[source]
Bases:
EncodingBase
Uses OpenFermion::bravyi_kitaev
- class tequila_code.quantumchemistry.encodings.BravyiKitaevFast(n_electrons, n_orbitals, up_then_down=False, *args, **kwargs)[source]
Bases:
EncodingBase
Uses OpenFermion::bravyi_kitaev_tree
- class tequila_code.quantumchemistry.encodings.BravyiKitaevTree(n_electrons, n_orbitals, up_then_down=False, *args, **kwargs)[source]
Bases:
EncodingBase
Uses OpenFermion::bravyi_kitaev_tree
- class tequila_code.quantumchemistry.encodings.EncodingBase(n_electrons, n_orbitals, up_then_down=False, *args, **kwargs)[source]
Bases:
object
- map_state(state: list, *args, **kwargs) list [source]
Expects a state in spin-orbital ordering Returns the corresponding qubit state in the class encoding :param state:
basis-state as occupation number vector in spin orbitals sorted as: [0_up, 0_down, 1_up, 1_down, … N_up, N_down] with N being the number of spatial orbitals
- Returns:
basis-state as qubit state in the corresponding mapping
- abstract me_to_jw() QCircuit [source]
This method needs to be implemented to enable default conversions via Jordan-Wigner
- property name
- property supports_ucc
- class tequila_code.quantumchemistry.encodings.JordanWigner(n_electrons, n_orbitals, up_then_down=False, *args, **kwargs)[source]
Bases:
EncodingBase
OpenFermion::jordan_wigner
- map_state(state: list, *args, **kwargs)[source]
Expects a state in spin-orbital ordering Returns the corresponding qubit state in the class encoding :param state:
basis-state as occupation number vector in spin orbitals sorted as: [0_up, 0_down, 1_up, 1_down, … N_up, N_down] with N being the number of spatial orbitals
- Returns:
basis-state as qubit state in the corresponding mapping
- class tequila_code.quantumchemistry.encodings.TaperedBravyKitaev(n_electrons, n_orbitals, active_fermions=None, active_orbitals=None, *args, **kwargs)[source]
Bases:
EncodingBase
- map_state(state: list, *args, **kwargs)[source]
Expects a state in spin-orbital ordering Returns the corresponding qubit state in the class encoding :param state:
basis-state as occupation number vector in spin orbitals sorted as: [0_up, 0_down, 1_up, 1_down, … N_up, N_down] with N being the number of spatial orbitals
- Returns:
basis-state as qubit state in the corresponding mapping
madness interface module
- class tequila_code.quantumchemistry.madness_interface.QuantumChemistryMadness(parameters: ParametersQC, transformation: str | Callable = None, active_orbitals: list = 'auto', executable: str = None, n_pno: int = None, n_virt: int = 0, keep_mad_files=False, datadir=None, *args, **kwargs)[source]
Bases:
QuantumChemistryBase
- compute_energy(method, *args, **kwargs)[source]
Call classical methods over PySCF (needs to be installed) or use as a shortcut to calculate quantum energies (see make_upccgsd_ansatz)
- Parameters:
method (method name) – classical: HF, MP2, CCSD, CCSD(T), FCI quantum: SPA-GASD (SPA can be dropped as well as letters in GASD) examples: GSD is the same as UpCCGSD, SPA alone is equivalent to SPA-D see make_upccgsd_ansatz of the this class for more information
args
kwargs
- get_pair_orbitals(i: OrbitalData, j: OrbitalData, exclude: List[OrbitalData] = None)[source]
- make_hardcore_boson_pno_upccd_ansatz(pairs=None, label=None, include_reference=True, direct_compiling=False)[source]
- make_spa_ansatz(label=None, hcb=False)[source]
Shortcut for convenience :param label: label for the angles :param hcb: if True the circuit will not map from HCB to JW (or other encodings that might be supported in the future)
- Return type:
Default SPA ansatz (equivalent to PNO-UpCCD with madness PNOs)
- make_upccgsd_ansatz(name='UpCCGSD', label=None, direct_compiling=None, order=None, neglect_z=None, hcb_optimization=None, include_reference=True, *args, **kwargs)[source]
Overwriting baseclass to allow names like : PNO-UpCCD etc :param label: :type label: label the variables of the ansatz ( variables will be labelled (indices, X, (label, layer) witch X=D/S) :param direct_compiling: :type direct_compiling: Directly compile the first layer (works only for transformation that implement the hcb_to_me function) :param name: if HCB is included in name: do not map from hard-core Boson to qubit encoding of this molecule
if SPA is included in name: Use the separable pair ansatz (excitations will be restricted to the PNO structure of the surrogate model) Excitations: can be “S” (use only singles), “D” (use only doubles), “GSD” (generalized singles and doubles), “GASD” (approximate singles, neglecting Z terms in JW)
- Parameters:
neglect_z (neglect all Z terms in singles excitations generators)
order (repetition of layers, can be given over the name as well, the order needs to be the first in the name then (i.e. 2-UpCCGSD, 2-SPA-GSD, etc))
args
kwargs
- make_upccgsd_indices(label=None, name='UpCCGD', exclude: list = None, *args, **kwargs)[source]
- Parameters:
label – label the angles
generalized – if true the complement to UpCCGD is created (otherwise UpCCD)
exclude – list of indices to exclude
- Returns:
All gates missing between PNO-UpCCD and UpCC(G)D
- perturbative_f12_correction(rdm1: ndarray = None, rdm2: ndarray = None, n_ri: int = None, f12_filename: str = 'molecule_f12tensor.bin', **kwargs) float [source]
Computes the spin-free [2]_R12 correction, needing only the 1- and 2-RDM of a reference method Requires either 1-RDM, 2-RDM or information to compute them in kwargs
- Parameters:
rdm1 – 1-electron reduced density matrix
rdm2 – 2-electron reduced density matrix
gamma – f12-exponent, for a correlation factor f_12 = -1/gamma * exp[-gamma*r_12]
n_ri – dimensionality of RI-basis; if None, then the maximum available via tensors / basis-set is used
f12_filename – when using madness_interface, <q|h|p> and <rs|1/r_12|pq> already available; need to provide f12-tensor <rs|f_12|pq> as “.bin” from madness or “.npy”, assuming Mulliken ordering
kwargs – e.g. RDM-information via {“U”: QCircuit, “variables”: optimal angles}, needs to be passed if rdm1,rdm2 not yet computed
- Return type:
the f12 correction for the energy
- plot2cube(orbital, filename=None, *args, **kwargs)[source]
plot orbitals to cube file (needs madtequila backend installed) :param method: if you want to plot frozen orbitals you can hand in a Tequila Orbital structure with idx_total defined :type method: orbital, the orbital index (starting from 0 on the active orbitals) :param filename: :type filename: name of the cubefile (default: mra_orbital_X.cube where X is the total index of the active orbital) :param args: :type args: further arguments for plot2cube :param kwargs further keyword arguments for plot2cube: :param see here for more https: :type see here for more https: //github.com/kottmanj/madness/tree/tequila/src/apps/plot
orbital optimizer module
- class tequila_code.quantumchemistry.orbital_optimizer.OptimizeOrbitalsResult(old_molecule: tequila_code.quantumchemistry.qc_base.QuantumChemistryBase = None, molecule: tequila_code.quantumchemistry.qc_base.QuantumChemistryBase = None, mcscf_object: object = None, mcscf_local_data: dict = None, energy: float = None, iterations: int = 0)[source]
Bases:
object
- energy: float = None
- iterations: int = 0
- mcscf_local_data: dict = None
- mcscf_object: object = None
- mo_coeff = None
- molecule: QuantumChemistryBase = None
- old_molecule: QuantumChemistryBase = None
- class tequila_code.quantumchemistry.orbital_optimizer.PySCFVQEWrapper(n_electrons: int = None, molecule_arguments: dict = None, rdm1: ~numpy.ndarray = None, rdm2: ~numpy.ndarray = None, one_body_integrals: ~numpy.ndarray = None, two_body_integrals: ~numpy.ndarray = None, history: list = <factory>, const_part: float = 0.0, silent: bool = False, vqe_solver: ~typing.Callable = None, circuit: ~tequila.circuit.circuit.QCircuit = None, vqe_solver_arguments: dict = <factory>, molecule_factory: ~typing.Callable = None)[source]
Bases:
object
Wrapper for tequila VQE’s to be compatible with PySCF orbital optimization
- circuit: QCircuit = None
- const_part: float = 0.0
- history: list
- molecule_arguments: dict = None
- molecule_factory: Callable = None
- n_electrons: int = None
- one_body_integrals: ndarray = None
- rdm1: ndarray = None
- rdm2: ndarray = None
- silent: bool = False
- two_body_integrals: ndarray = None
- vqe_solver: Callable = None
- vqe_solver_arguments: dict
- tequila_code.quantumchemistry.orbital_optimizer.optimize_orbitals(molecule, circuit=None, vqe_solver=None, pyscf_arguments=None, silent=False, vqe_solver_arguments=None, initial_guess=None, return_mcscf=False, use_hcb=False, molecule_factory=None, molecule_arguments=None, restrict_to_active_space=True, *args, **kwargs)[source]
- Parameters:
molecule (The tequila molecule whose orbitals are to be optimized)
circuit (The circuit that defines the ansatz to the wavefunction in the VQE) – can be None, if a customized vqe_solver is passed that can construct a circuit
vqe_solver (The VQE solver (the default - vqe_solver=None - will take the given circuit and construct an expectationvalue out of molecule.make_hamiltonian and the given circuit)) – A customized object can be passed that needs to be callable with the following signature: vqe_solver(H=H, circuit=self.circuit, molecule=molecule, **self.vqe_solver_arguments)
pyscf_arguments (Arguments for the MCSCF structure of PySCF, if None, the defaults are {“max_cycle_macro”:10, “max_cycle_micro”:3} (see here https://pyscf.org/pyscf_api_docs/pyscf.mcscf.html))
silent (silence printout)
use_hcb (indicate if the circuit is in hardcore Boson encoding)
vqe_solver_arguments (Optional arguments for a customized vqe_solver or the default solver) – for the default solver: vqe_solver_arguments={“optimizer_arguments”:A, “restrict_to_hcb”:False} where A holds the kwargs for tq.minimize restrict_to_hcb keyword controls if the standard (in whatever encoding the molecule structure has) Hamiltonian is constructed or the hardcore_boson hamiltonian
initial_guess (Initial guess for the MCSCF module of PySCF (Matrix of orbital rotation coefficients)) –
The default (None) is a unit matrix predefined commands are
initial_guess=”random” initial_guess=”random_loc=X_scale=Y” with X and Y being floats This initialized a random guess using numpy.random.normal(loc=X, scale=Y) with X=0.0 and Y=0.1 as defaults
return_mcscf (return the PySCF MCSCF structure after optimization)
molecule_arguments (arguments to pass to molecule_factory or default molecule constructor | only change if you know what you are doing)
args (just here for convenience)
kwargs (just here for conveniece)
- Return type:
Optimized Tequila Molecule
psi4 interface module
- exception tequila_code.quantumchemistry.psi4_interface.OpenVQEEPySCFException(msg)[source]
Bases:
TequilaException
- class tequila_code.quantumchemistry.psi4_interface.Psi4Results(variables: dict = None, filename: str = None, wfn: psi4.core.Wavefunction | psi4.core.CCWavefunction | psi4.core.CIWavefunction = None, mol: psi4.core.Molecule = None)[source]
Bases:
object
- filename: str = None
- mol: Molecule = None
- variables: dict = None
- wfn: Wavefunction | CCWavefunction | CIWavefunction = None
- class tequila_code.quantumchemistry.psi4_interface.QuantumChemistryPsi4(parameters: ParametersQC, transformation: str | Callable = None, active_orbitals=None, reference_orbitals=None, frozen_orbitals=None, *args, **kwargs)[source]
Bases:
QuantumChemistryBase
- compute_amplitudes(method: str, options: dict = None, filename: str = None, *args, **kwargs) Amplitudes | ClosedShellAmplitudes [source]
Compute closed-shell CC amplitudes
- Parameters:
method – coupled-cluster methods like cc2, ccsd, cc3, ccsd(t) Success might depend on backend got an extra function for MP2
*args
**kwargs
- compute_energy(method: str = 'fci', options=None, recompute: bool = True, ignore_active_space=False, *args, **kwargs)[source]
Call classical methods over PySCF (needs to be installed) or use as a shortcut to calculate quantum energies (see make_upccgsd_ansatz)
- Parameters:
method (method name) – classical: HF, MP2, CCSD, CCSD(T), FCI – with pyscf quantum: UpCCD, UpCCSD, UpCCGSD, k-UpCCGSD, UCCSD, see make_upccgsd_ansatz of the this class for more information
args
kwargs (for quantum methods, keyword arguments for minimizer)
- compute_rdms(U: QCircuit = None, variables: Variables = None, spin_free: bool = True, get_rdm1: bool = True, get_rdm2: bool = True, psi4_method: str = None, psi4_options: dict = {}, *args, **kwargs)[source]
Same functionality as qc_base.compute_rdms (look there for more information), plus the additional option to compute 1- and 2-RDM using psi4 by the keyword psi4_rdms
- Parameters:
U – Quantum Circuit to achieve the desired state psi = U |0rangle, optional if psi4_rdms is set to True
variables – If U is parametrized, then need to hand over a set of fixed variables
spin_free – Set whether matrices should be spin-free (summation over spin) or defined by spin-orbitals
get_rdm1 – Set whether either one or both rdm1, rdm2 should be computed. If both are needed at some point, it is recommended to compute them at once. Note that whatever is specified in psi4_options has priority.
get_rdm2 – Set whether either one or both rdm1, rdm2 should be computed. If both are needed at some point, it is recommended to compute them at once. Note that whatever is specified in psi4_options has priority.
psi4_method – Method to be run, currently only methods returning a CIWavefuntion are supported (e.g. “detci” + ex_level in options, or “fci”, “cisdt”, “casscf”, but NOT “cisd”)
psi4_options – Options to be handed over to psi4, containing e.g. excitation level of “detci”-method. If “detci__opdm” for 1-RDM and “detci__tpdm” for 2-RDM are not included, the keywords get_rdm1, get_rdm2 are used (if both are specified, prioritizing psi4_options).
- initialize_integral_manager(*args, **kwargs)[source]
Called by self.__init__() with args and kwargs passed through Override this in derived class such that it returns an intitialized instance of the integral manager
In the BaseClass it is required to pass the following with kwargs on init: - one_body_integrals as matrix - two_body_integrals as NBTensor of numpy.ndarray (four indices, openfermion ordering) - nuclear_repulsion (constant part of hamiltonian - optional)
Method sets: - result of self.get_integrals()
- property nirrep
- orbital_energies(irrep: int | str = None, beta: bool = False, wfn=None)[source]
Returns orbital energies of a given irrep or all orbital energies of all irreps (default)
- Parameters:
irrep (int or str :) – int: specify the irrep by number (in cotton ordering) str: specify the irrep by name (like ‘A1’) specify from which irrep you want the orbital energies psi4 orders irreps in ‘Cotton ordering’ http://www.psicode.org/psi4manual/master/psithonmol.html#table-irrepordering
beta (bool : (Default value=False)) – get the beta electrons
- Return type:
list or orbital energies
- perturbative_f12_correction(rdm1: ndarray = None, rdm2: ndarray = None, gamma: float = 1.4, n_ri: int = None, cabs_type: str = 'active', cabs_options: dict = None, **kwargs) float [source]
Computes the spin-free [2]_R12 correction, needing only the 1- and 2-RDM of a reference method Requires either 1-RDM, 2-RDM or information to compute them in kwargs
- Parameters:
rdm1 – 1-electron reduced density matrix
rdm2 – 2-electron reduced density matrix
gamma – f12-exponent, for a correlation factor f_12 = -1/gamma * exp[-gamma*r_12]
n_ri – dimensionality of RI-basis; if None, then the maximum available via tensors / basis-set is used
cabs_type –
either “active” for using a given basis set as is as approximative CBS (complete basis set), and specify
OBS (orbital basis) by an active space - or “cabs+” for CABS+-approach as in
Valeev, E. F. (2004). Improving on the resolution of the identity in linear R12 ab initio theories. Chemical Physics Letters, 395(4–6), 190–195. https://doi.org/10.1016/j.cplett.2004.07.061 -> pass cabs_name in cabs_options
cabs_options – dict, which needs at least {“cabs_name”: some CABS basis set} if cabs_type==”cabs+”
kwargs – e.g. RDM-information via {“U”: QCircuit, “variables”: optimal angles} if computation via VQE, or {“rdm__psi4_method”: some CI method, “rdm__psi4_options”: dict with psi4 options} if computation via psi4, compare to psi4_interface.compute_rdms one of the above needs to be passed if rdm1,rdm2 not yet computed
- Return type:
the f12 correction for the energy
- property point_group
- property rdm1: tuple
Returns RMD1 if computed with compute_rdms function before
- property rdm2: tuple
Returns RMD2 if computed with compute_rdms function before This is returned in Dirac (physics) notation by default (can be changed in compute_rdms with keyword)!
pyscf interface module
- exception tequila_code.quantumchemistry.pyscf_interface.OpenVQEEPySCFException(msg)[source]
Bases:
TequilaException
- class tequila_code.quantumchemistry.pyscf_interface.QuantumChemistryPySCF(parameters: ParametersQC, transformation: str | Callable = None, *args, **kwargs)[source]
Bases:
QuantumChemistryBase
- compute_energy(method: str, *args, **kwargs) float [source]
Call classical methods over PySCF (needs to be installed) or use as a shortcut to calculate quantum energies (see make_upccgsd_ansatz)
- Parameters:
method (method name) – classical: HF, MP2, CCSD, CCSD(T), FCI – with pyscf quantum: UpCCD, UpCCSD, UpCCGSD, k-UpCCGSD, UCCSD, see make_upccgsd_ansatz of the this class for more information
args
kwargs (for quantum methods, keyword arguments for minimizer)
qc base module
- class tequila_code.quantumchemistry.qc_base.QuantumChemistryBase(parameters: ParametersQC, transformation: str | Callable = None, active_orbitals: list = None, frozen_orbitals: list = None, orbital_type: str = None, reference_orbitals: list = None, orbitals: list = None, *args, **kwargs)[source]
Bases:
object
Base Class for tequila chemistry functionality This is what is initialized with tq.Molecule(…) We try to define all main methods here and only implemented specializations in the derived classes Derived classes interface specific backends (e.g. Psi4, PySCF and Madness). See PACKAGE_interface.py for more
- UC(i, j, angle=None, label=None, control=None, assume_real=True, *args, **kwargs)[source]
Convenience function for orbital correlator circuit (correlating spatial orbital i and j through a spin-paired double excitation) with standard naming of variables See arXiv:2207.12421 Eq.22 for UC(1,2)
Parameters:
- indices:
tuple of two spatial(!) orbital indices
- angle:
Numeric or hashable type or tequila objective. Default is None and results in automatic naming as (“R”,i,j)
- label:
can be passed instead of angle to have auto-naming with label (“R”,i,j,label) useful for repreating gates with individual variables
- control:
List of possible control qubits
- assume_real:
Assume that the wavefunction will always stay real. Will reduce potential gradient costs by a factor of 2
- UR(i, j, angle=None, label=None, control=None, assume_real=True, *args, **kwargs)[source]
Convenience function for orbital rotation circuit (rotating spatial orbital i and j) with standard naming of variables See arXiv:2207.12421 Eq.6 for UR(0,1) Parameters: ———-
- indices:
tuple of two spatial(!) orbital indices
- angle:
Numeric or hashable type or tequila objective. Default is None and results in automatic naming as (“R”,i,j)
- label:
can be passed instead of angle to have auto-naming with label (“R”,i,j,label) useful for repreating gates with individual variables
- control:
List of possible control qubits
- assume_real:
Assume that the wavefunction will always stay real. Will reduce potential gradient costs by a factor of 2
- property active_space
- compute_amplitudes(method: str, *args, **kwargs)[source]
Compute closed-shell CC amplitudes
- Parameters:
method – coupled-cluster methods like cc2, ccsd, cc3, ccsd(t) Success might depend on backend got an extra function for MP2
*args
**kwargs
- compute_ccsd_amplitudes() ClosedShellAmplitudes [source]
- compute_cis_amplitudes()[source]
Compute the CIS amplitudes of the molecule Warning: Not field tested!
- compute_energy(method, *args, **kwargs)[source]
Call classical methods over PySCF (needs to be installed) or use as a shortcut to calculate quantum energies (see make_upccgsd_ansatz)
- Parameters:
method (method name) – classical: HF, MP2, CCSD, CCSD(T), FCI – with pyscf quantum: UpCCD, UpCCSD, UpCCGSD, k-UpCCGSD, UCCSD, see make_upccgsd_ansatz of the this class for more information
args
kwargs (for quantum methods, keyword arguments for minimizer)
- compute_mp2_amplitudes(hf_energy=None, return_energy=False) ClosedShellAmplitudes [source]
Compute closed-shell mp2 amplitudes (canonical amplitudes only)
\[t(a,i,b,j) = 0.25 * g(a,i,b,j)/(e(i) + e(j) -a(i) - b(j) )\]- Returns:
- compute_rdms(U: QCircuit = None, variables: Variables = None, spin_free: bool = True, get_rdm1: bool = True, get_rdm2: bool = True, ordering='dirac', use_hcb: bool = False, rdm_trafo: QubitHamiltonian = None, evaluate=True)[source]
Computes the one- and two-particle reduced density matrices (rdm1 and rdm2) given a unitary U. This method uses the standard ordering in physics as denoted below. Note, that the representation of the density matrices depends on the qubit transformation used. The Jordan-Wigner encoding corresponds to ‘classical’ second quantized density matrices in the occupation picture.
We only consider real orbitals and thus real-valued RDMs. The matrices are set as private members _rdm1, _rdm2 and can be accessed via the properties rdm1, rdm2.
- Parameters:
U – Quantum Circuit to achieve the desired state psi = U |0rangle, non-optional
variables – If U is parametrized, then need to hand over a set of fixed variables
spin_free – Set whether matrices should be spin-free (summation over spin) or defined by spin-orbitals
get_rdm1 – Set whether either one or both rdm1, rdm2 should be computed. If both are needed at some point, it is recommended to compute them at once.
get_rdm2 – Set whether either one or both rdm1, rdm2 should be computed. If both are needed at some point, it is recommended to compute them at once.
rdm_trafo – The rdm operators can be transformed, e.g., a^dagger_i a_j -> U^dagger a^dagger_i a_j U, where U represents the transformation. The default is set to None, implying that U equas the identity.
evaluate – if true, the tequila expectation values are evaluated directly via the tq.simulate command. the protocol is optimized to avoid repetation of wavefunction simulation if false, the rdms are returned as tq.QTensors
- do_make_molecule(*args, **kwargs)[source]
Called by self.make_molecule with args and kwargs passed through Override this in derived class if needed
- format_excitation_indices(idx)[source]
Consistent formatting of excitation indices idx = [(p0,q0),(p1,q1),…,(pn,qn)] sorted as: p0<p1<pn and pi<qi :param idx: list of index tuples describing a single(!) fermionic excitation :return: tuple-list of index tuples
- classmethod from_openfermion(molecule: MolecularData, transformation: str | Callable = None, *args, **kwargs)[source]
Initialize direclty from openfermion MolecularData object
- Parameters:
molecule – The openfermion molecule
- Return type:
The Tequila molecule
- get_givens_circuit(unitary, tol=1e-12, ordering='Optimized')[source]
Constructs a quantum circuit from a given real unitary matrix using Givens rotations.
This method decomposes a unitary matrix into a series of Givens and Rz (phase) rotations, then constructs and returns a quantum circuit that implements this sequence of rotations.
Parameters: - unitary (numpy.array): A real unitary matrix representing the transformation to implement. - tol (float): A tolerance threshold below which matrix elements are considered zero. - ordering (list of tuples or ‘Optimized’): Custom ordering of indices for Givens rotations or ‘Optimized’ to generate them automatically.
Returns: - QCircuit: A quantum circuit implementing the series of rotations decomposed from the unitary.
- get_integrals(*args, **kwargs)[source]
Returns
options for kwargs: “ordering = [“openfermion”, “chem”, “phys”], ignore_active_space = [True, False]”
Tuple with: constant part (nuclear_repulsion + possible integrated parts from active-spaces) one_body_integrals two_body_integrals
- get_pair_specific_indices(pair_info: str = None, include_singles: bool = True, general_excitations: bool = True) list [source]
Assuming a pair-specific model, create a pair-specific index list to be used in make_upccgsd_ansatz(indices = … ) Excite from a set of references (i) to any pair coming from (i), i.e. any (i,j)/(j,i). If general excitations are allowed, also allow excitations from pairs to appendant pairs and reference.
- pair_info
file or list including information about pair structure references single number, pair double example: as file: “0,1,11,11,00,10” (hand over file name)
in file, skip first row assuming some text with information as list:[‘0’,’1`’,’11’,’11’,’00’,’10’] ~> two reference orbitals 0 and 1, then two orbitals from pair 11, one from 00, one mixed 10
- include_singles
include single excitations
- general_excitations
allow general excitations
- Returns
list of indices with pair-specific ansatz
- hcb_to_me(U=None, condensed=False)[source]
Transform a circuit in the hardcore-boson encoding (HCB) to the encoding of this molecule HCB is supposed to be encoded on the first n_orbitals qubits :param U: :type U: HCB circuit (using the alpha qubits) :param condensed: :type condensed: assume that incoming U is condensed (HCB on the first n_orbitals; and not, as for example in JW on the first n even orbitals)
- initialize_integral_manager(*args, **kwargs)[source]
Called by self.__init__() with args and kwargs passed through Override this in derived class such that it returns an intitialized instance of the integral manager
In the BaseClass it is required to pass the following with kwargs on init: - one_body_integrals as matrix - two_body_integrals as NBTensor of numpy.ndarray (four indices, openfermion ordering) - nuclear_repulsion (constant part of hamiltonian - optional)
Method sets: - result of self.get_integrals()
- make_annihilation_op(orbital, coefficient=1.0)[source]
Compute annihilation operator on spin-orbital in qubit representation Spin-orbital order is always (up,down,up,down,…)
- make_ansatz(name: str, *args, **kwargs)[source]
Automatically calls the right subroutines to construct ansatze implemented in tequila.chemistry name: namne of the ansatz, examples are: UpCCGSD, UpCCD, SPA, UCCSD, SPA+UpCCD, SPA+GS
- make_creation_op(orbital, coefficient=1.0)[source]
Compute creation operator on spin-orbital in qubit representation Spin-orbital order is always (up,down,up,down,…)
- make_excitation_gate(indices, angle, control=None, assume_real=True, **kwargs)[source]
Initialize a fermionic excitation gate defined as
\[e^{-i\frac{a}{2} G}\]with generator defines by the indices [(p0,q0),(p1,q1),…] .. math:
G = i(\prod_{k} a_{p_k}^\dagger a_{q_k} - h.c.)
- Parameters:
indices – List of tuples that define the generator
angle – Numeric or hashable type or tequila objective
control – List of possible control qubits
assume_real – Assume that the wavefunction will always stay real. Will reduce potential gradient costs by a factor of 2
- make_excitation_generator(indices: Iterable[Tuple[int, int]], form: str = None, remove_constant_term: bool = True) QubitHamiltonian [source]
Notes
- Creates the transformed hermitian generator of UCC type unitaries:
M(a^dagger_{a_0} a_{i_0} a^dagger{a_1}a_{i_1} … - h.c.) where the qubit map M depends is self.transformation
- Parameters:
indices (Iterable[Tuple[int, int]] :) – List of tuples [(a_0, i_0), (a_1, i_1), … ] - recommended format, in spin-orbital notation (alpha odd numbers, beta even numbers) can also be given as one big list: [a_0, i_0, a_1, i_1 …]
form (str : (Default value None):) – Manipulate the generator to involution or projector set form=’involution’ or ‘projector’ the default is no manipulation which gives the standard fermionic excitation operator back
remove_constant_term (bool: (Default value True):) – by default the constant term in the qubit operator is removed since it has no effect on the unitary it generates if the unitary is controlled this might not be true!
- Returns:
1j*Transformed qubit excitation operator, depends on self.transformation
- Return type:
type
- make_hamiltonian(*args, **kwargs) QubitHamiltonian [source]
- Parameters:
occupied_indices (will be auto-assigned according to specified active space. Can be overridden by passing specific lists (same as in open fermion))
active_indices (will be auto-assigned according to specified active space. Can be overridden by passing specific lists (same as in open fermion))
- Return type:
Qubit Hamiltonian in the Fermion-to-Qubit transformation defined in self.parameters
- make_hardcore_boson_excitation_gate(indices, angle, control=None, assume_real=True, compile_options='optimize')[source]
Make excitation generator in the hardcore-boson approximation (all electrons are forced to spin-pairs) use only in combination with make_hardcore_boson_hamiltonian()
- Parameters:
indices
angle
control
assume_real
compile_options
- make_hardcore_boson_hamiltonian(condensed=False)[source]
- Returns:
Hamiltonian in Hardcore-Boson approximation (electrons are forced into spin-pairs)
Indepdent of Fermion-to-Qubit mapping
condensed (always give Hamiltonian back from qubit 0 to N where N is the number of orbitals)
if condensed=False then JordanWigner would give back the Hamiltonian defined on even qubits between 0 to 2N
- make_hardcore_boson_upccgd_layer(indices: list = 'UpCCGD', label: str = None, assume_real: bool = True, *args, **kwargs)[source]
- make_molecular_hamiltonian(occupied_indices=None, active_indices=None)[source]
- Returns:
Create a MolecularHamiltonian as openfermion Class
(used internally here, not used in tequila)
- make_molecule(*args, **kwargs) MolecularData [source]
Creates a molecule in openfermion format by running psi4 and extracting the data Will check for previous outputfiles before running Will not recompute if a file was found
- Parameters:
parameters – An instance of ParametersQC, which also holds an instance of ParametersPsi4 via parameters.psi4 The molecule will be saved in parameters.filename, if this file exists before the call the molecule will be imported from the file
- Returns:
the molecule in openfermion.MolecularData format
- Return type:
type
- make_number_op(orbital)[source]
Compute number operator on spin-orbital in qubit representation Spin-orbital order is always (up,down,up,down,…)
- make_spa_ansatz(edges, hcb=False, use_units_of_pi=False, label=None, optimize=None, ladder=True)[source]
Separable Pair Ansatz (SPA) for general molecules see arxiv: edges: a list of tuples that contain the orbital indices for the specific pairs
one example: edges=[(0,), (1,2,3), (4,5)] are three pairs, one with a single orbital [0], one with three orbitals [1,2,3] and one with two orbitals [4,5]
hcb: spa ansatz in the hcb (hardcore-boson) space without transforming to current transformation (e.g. JordanWigner), use this for example in combination with the self.make_hardcore_boson_hamiltonian() and see the article above for more info use_units_of_pi: circuit angles in units of pi label: label the variables in the circuit optimize: optimize the circuit construction (see article). Results in shallow circuit from Ry and CNOT gates ladder: if true the excitation pattern will be local. E.g. in the pair from orbitals (1,2,3) we will have the excitations 1->2 and 2->3, if set to false we will have standard coupled-cluster style excitations - in this case this would be 1->2 and 1->3
- make_uccsd_ansatz(trotter_steps: int = 1, initial_amplitudes: str | Amplitudes | ClosedShellAmplitudes = None, include_reference_ansatz=True, parametrized=True, threshold=1e-08, add_singles=None, screening=True, *args, **kwargs) QCircuit [source]
- Parameters:
initial_amplitudes (Union[str :) – initial amplitudes given as ManyBodyAmplitudes structure or as string where ‘mp2’, ‘cc2’ or ‘ccsd’ are possible initializations
include_reference_ansatz – Also do the reference ansatz (prepare closed-shell Hartree-Fock) (Default value = True)
parametrized – Initialize with variables, otherwise with static numbers (Default value = True)
trotter_steps (int :)
initial_amplitudes
Amplitudes
ClosedShellAmplitudes] – (Default value = “cc2”)
- Returns:
Parametrized QCircuit
- Return type:
type
- make_upccgsd_ansatz(include_reference: bool = True, name: str = 'UpCCGSD', label: str = None, order: int = None, assume_real: bool = True, hcb_optimization: bool = None, spin_adapt_singles: bool = True, neglect_z: bool = False, mix_sd: bool = False, *args, **kwargs)[source]
UpGCCSD Ansatz similar as described by Lee et. al.
- Parameters:
include_reference – include the HF reference state as initial state
indices – pass custom defined set of indices from which the ansatz will be created List of tuples of tuples spin-indices e.g. [((2*p,2*q),(2*p+1,2*q+1)), …]
label – An additional label that is set with the variables default is None and no label will be set: variables names will be (x, (p,q)) for x in range(order) with a label the variables will be named (label, (x, (p,q)))
order – Order of the ansatz (default is 1) determines how often the ordering gets repeated parameters of repeating layers are independent
assume_real – assume a real wavefunction (that is always the case if the reference state is real) reduces potential gradient costs from 4 to 2
mix_sd – Changes the ordering from first all doubles and then all singles excitations (DDDDD….SSSS….) to a mixed order (DS-DS-DS-DS-…) where one DS pair acts on the same MOs. Useful to consider when systems with high electronic correlation and system high error associated with the no Trotterized UCC.
- Return type:
UpGCCSD ansatz
- make_upccgsd_layer(indices, include_singles: bool = True, include_doubles: bool = True, assume_real: bool = True, label=None, spin_adapt_singles: bool = True, angle_transform=None, mix_sd: bool = False, neglect_z: bool = False, *args, **kwargs)[source]
- make_upccgsd_singles(indices='UpCCGSD', spin_adapt_singles=True, label=None, angle_transform=None, assume_real=True, neglect_z=False, *args, **kwargs)[source]
- property n_electrons: int
rtype: The number of active electrons in this molecule
- property n_orbitals: int
rtype: The number of active orbitals in this Molecule
- n_rotation(i, phi)[source]
Creates a quantum circuit that applies a phase rotation based on phi to both components (up and down) of a given qubit.
Parameters: - i (int): The index of the qubit to which the rotation will be applied. - phi (float): The rotation angle. The actual rotation applied will be multiplied with -2 for both components.
Returns: - QCircuit: A quantum circuit object containing the sequence of rotations applied to the up and down components of the specified qubit.
- property orbitals
- perturbative_f12_correction(rdm1: ndarray = None, rdm2: ndarray = None, gamma: float = 1.4, n_ri: int = None, external_info: dict = None, **kwargs) float [source]
Computes the spin-free [2]_R12 correction, needing only the 1- and 2-RDM of a reference method Requires either 1-RDM, 2-RDM or information to compute them in kwargs
- Parameters:
rdm1 – 1-electron reduced density matrix
rdm2 – 2-electron reduced density matrix
gamma – f12-exponent, for a correlation factor f_12 = -1/gamma * exp[-gamma*r_12]
n_ri – dimensionality of RI-basis; specify only, if want to truncate available RI-basis if None, then the maximum available via tensors / basis-set is used must not be larger than size of available RI-basis, and not smaller than size of OBS for n_ri==dim(OBS), the correction returns zero
external_info – for usage in qc_base, need to provide information where to find one-body tensor f12-tensor <rs|f_12|pq>; pass dictionary with {“f12_filename”: where to find f12-tensor, “scheme”: ordering scheme of tensor}
kwargs – e.g. RDM-information via {“U”: QCircuit, “variables”: optimal angles}, needs to be passed if rdm1,rdm2 not yet computed
- Return type:
the f12 correction for the energy
- prepare_hardcore_boson_reference()[source]
Prepare reference state in the Hardcore-Boson approximation (eqch qubit represents two spin-paired electrons) :rtype: tq.QCircuit that prepares the HCB reference
- prepare_reference(state=None, *args, **kwargs)[source]
- Return type:
A tequila circuit object which prepares the reference of this molecule in the chosen transformation
- property rdm1
Returns RMD1 if computed with compute_rdms function before
- property rdm2
Returns RMD2 if computed with compute_rdms function before This is returned in Dirac (physics) notation by default (can be changed in compute_rdms with keyword)!
- rdm_spinsum(sum_rdm1: bool = True, sum_rdm2: bool = True) tuple [source]
Given the spin-ful 1- and 2-particle reduced density matrices, compute the spin-free RDMs by spin summation.
- Parameters:
sum_rdm1 – If set to true, perform spin summation on rdm1, rdm2
sum_rdm2 – If set to true, perform spin summation on rdm1, rdm2
- Returns:
The desired spin-free matrices
- Return type:
rdm1_spinsum, rdm2_spinsum
- property reference_orbitals
- supports_ucc()[source]
check if the current molecule supports UCC operations (e.g. mol.make_excitation_gate)
- transform_orbitals(orbital_coefficients, ignore_active_space=False, name=None, *args, **kwargs)[source]
- Parameters:
orbital_coefficients (second index is new orbital indes, first is old orbital index (summed over), indices are assumed to be defined on the active space)
ignore_active_space (if true orbital_coefficients are not assumed to be given in the active space)
name (str, name the new orbitals)
args
kwargs
- Return type:
New molecule with transformed orbitals
- tequila_code.quantumchemistry.qc_base.get_givens_decomposition(unitary, tol=1e-12, ordering='Optimized', return_diagonal=False)[source]
Decomposes a real unitary matrix into Givens rotations (theta) and Rz rotations (phi).
Parameters: - unitary (numpy.array): A real unitary matrix to decompose. It cannot be complex. - tol (float): Tolerance for considering matrix elements as zero. Elements with absolute value less than tol are treated as zero. - ordering (list of tuples or ‘Optimized’): Custom ordering of indices for Givens rotations or ‘Optimized’ to generate them automatically. - return_diagonal (bool): If True, the function also returns the diagonal matrix as part of the output.
Returns: - list: A list of tuples, each representing a Givens rotation. Each tuple contains the rotation angle theta and indices (i,j) of the rotation. - list: A list of tuples, each representing an Rz rotation. Each tuple contains the rotation angle phi and the index (i) of the rotation. - numpy.array (optional): The diagonal matrix after applying all Givens rotations, returned if return_diagonal is True.
- tequila_code.quantumchemistry.qc_base.givens_matrix(n, p, q, theta)[source]
Construct a complex Givens rotation matrix of dimension n by theta between rows/columns p and q.
- tequila_code.quantumchemistry.qc_base.reconstruct_matrix_from_givens(n, theta_list, phi_list, to_real_if_possible=True, tol=1e-12)[source]
Reconstructs a matrix from given Givens rotations and Rz diagonal rotations. This function is effectively an inverse of get_givens_decomposition, and therefore only works with data in the same format as its output.
Parameters: - n (int): The size of the unitary matrix to be reconstructed. - theta_list (list of tuples): Each tuple contains (angle, i, j) representing a Givens rotation of angle radians, applied to rows/columns i and j. - phi_list (list of tuples): Each tuple contains (angle, i), representing an Rz rotation by angle radians applied to the `i`th diagonal element. - to_real_if_possible (bool): If True, converts the matrix to real if its imaginary part is effectively zero. - tol (float): The tolerance whether to swap a complex rotation for a sign change.
Returns: - numpy.ndarray: The reconstructed complex or real matrix, depending on the to_real_if_possible flag and matrix composition.
Module contents
- tequila_code.quantumchemistry.Molecule(geometry: str = None, basis_set: str = None, transformation: str | Callable = None, orbital_type: str = None, backend: str = None, guess_wfn=None, name: str = None, *args, **kwargs) QuantumChemistryBase [source]
- Parameters:
geometry – molecular geometry as string or as filename (needs to be in xyz format with .xyz ending)
basis_set – quantum chemistry basis set (sto-3g, cc-pvdz, etc)
transformation – The Fermion to Qubit Transformation (jordan-wigner, bravyi-kitaev, bravyi-kitaev-tree and whatever OpenFermion supports)
backend – quantum chemistry backend (psi4, pyscf)
guess_wfn – pass down a psi4 guess wavefunction to start the scf cycle from can also be a filename leading to a stored wavefunction
name – name of the molecule, if not given it’s auto-deduced from the geometry can also be done vice versa (i.e. geometry is then auto-deduced to name.xyz)
args
kwargs
- Return type:
The Fermion to Qubit Transformation (jordan-wigner, bravyi-kitaev, bravyi-kitaev-tree and whatever OpenFermion supports)
- tequila_code.quantumchemistry.MoleculeFromOpenFermion(molecule, transformation: str | Callable = None, backend: str = None, *args, **kwargs) QuantumChemistryBase [source]
Initialize a tequila Molecule directly from an openfermion molecule object :param molecule: The openfermion molecule :param transformation: The Fermion to Qubit Transformation (jordan-wigner, bravyi-kitaev, bravyi-kitaev-tree and whatever OpenFermion supports) :param backend: The quantum chemistry backend, can be None in this case
- Return type:
The tequila molecule