tangelo.toolboxes.ansatz_generator package

Subpackages

Submodules

tangelo.toolboxes.ansatz_generator.adapt_ansatz module

This module defines the adaptive ansatz class.

class tangelo.toolboxes.ansatz_generator.adapt_ansatz.ADAPTAnsatz(n_spinorbitals, n_electrons, spin, ansatz_options=None)

Bases: Ansatz

Adaptive ansatz used with ADAPT-VQE. This Ansatz class has methods to take a (or many) QubitOperator, transform it (them) into a circuit and append it (them). The number of variational parameters corresponds to the number of terms added to the Ansatz.

n_spinorbitals

Number of spin orbitals in a given basis.

Type:

int

n_electrons

Number of electrons.

Type:

int

spin

Spin of system.

Type:

int

operators

List of operators to consider at the construction step. Can be useful for restarting computation.

Type:

list of QubitOperator

ferm_operators

Same as operators, but in fermionic form. Not necessarily for running the ansatz, but it is convenient for analyzing results.

Type:

list of FermionOperator

mapping

Qubit encoding.

Type:

string

up_then_down

Ordering convention.

Type:

bool

var_params

Variational parameters.

Type:

list of float

circuit

Quantum circuit defined by a list of Gates.

Type:

Circuit

add_operator(pauli_operator, ferm_operator=None)

Add a new operator to our circuit.

Parameters:
  • pauli_operator (QubitOperator) – Operator to convert into a circuit and append it to the present circuit.

  • ferm_operator (FermionicOperator) – Same operator in fermionic form.

build_circuit(var_params=None)

Construct the variational circuit to be used as our ansatz.

property n_var_params
prepare_reference_state()

Prepare a circuit generating the HF reference state.

set_var_params(var_params=None)

Set initial variational parameter values. Defaults to zeros.

update_var_params(var_params)

Update variational parameters (done repeatedly during VQE).

tangelo.toolboxes.ansatz_generator.ansatz module

This module defines the ansatz abstract class, providing the foundation to implement variational ansatz circuits.

class tangelo.toolboxes.ansatz_generator.ansatz.Ansatz

Bases: ABC

Base class for all Ansatz. Derived/children classes wirtten by users and developers must implement the following abstract methods.

abstract build_circuit()

Build and return the quantum circuit implementing the ansatz.

abstract prepare_reference_state()

Return circuit preparing the desired reference wavefunction (HF, multi-reference state…).

abstract set_var_params()

Initialize variational parameters as zeros, random numbers, MP2, or any insightful values. Impacts the convergence of variational algorithms.

abstract update_var_params()

Update value of variational parameters in the already-built ansatz circuit member.

tangelo.toolboxes.ansatz_generator.ansatz_utils module

Provide useful functions, corresponding to common patterns in quantum chemistry circuits (CNOT ladders, Pauli-word to circuit translation …) to facilitate the assembly of ansatz quantum circuits.

tangelo.toolboxes.ansatz_generator.ansatz_utils.append_qft_rotations_gates(gate_list, qubit_list, prefac=1)

Appends the list of gates required for a quantum fourier transform to a gate list.

Parameters:
  • gate_list (list) – List of Gate elements

  • qubit_list (list) – List of integers for which the qft operations are performed

Returns:

list – List of Gate objects for rotation portion of qft circuit appended to gate_list

tangelo.toolboxes.ansatz_generator.ansatz_utils.controlled_pauliwords(qubit_op, control, n_qubits=None)

Takes a qubit operator and returns controlled-pauliword circuits for each term as a list.

Parameters:
  • qubit_op (QubitOperator) – The qubit operator with pauliwords to generate circuits for

  • control (int) – The index of the control qubit

  • n_qubits (int) – When generating each Circuit, create with n_qubits size

Returns:

list – List of controlled-pauliword Circuit for each pauliword in the qubit_op

tangelo.toolboxes.ansatz_generator.ansatz_utils.controlled_swap_to_XX_gates(c, n1, n2)

Equivalent decomposition of controlled swap into 1-qubit gates and XX 2-qubit gate.

This is useful for IonQ experiments as the native two-qubit gate is the XX Ising coupling.

Parameters:
  • c (int) – control qubit

  • n1 (int) – first target qubit

  • n2 (int) – second target qubit

Returns:

list – List of Gate that applies controlled swap operation

tangelo.toolboxes.ansatz_generator.ansatz_utils.derangement_circuit(qubit_list, control=None, n_qubits=None, decomp=None)

Returns the (controlled-)derangement circuit for multiple copies of a state

Parameters:
  • qubit_list (list of list(int)) – Each item in the list is a list of qubit registers for each copy. The length of each list of qubit registers must be the same. For example [[1, 2], [3, 4]] applies controlled-swaps between equivalent states located on qubits [1, 2] and [3, 4]

  • control (int) – The control register to be measured.

  • n_qubits (int) – The number of qubits in the circuit.

  • decomp (str) – Use the decomposed controlled-swap into 1-qubit gates and a certain 2-qubit gate listed below. “XX”: 2-qubit gate is XX

Returns:

Circuit – The derangement circuit

tangelo.toolboxes.ansatz_generator.ansatz_utils.exp_pauliword_to_gates(pauli_word, coef, variational=True, control=None)

Generate a list of Gate objects corresponding to the exponential of a pauli word. The process is described in Whitfield 2010 https://arxiv.org/pdf/1001.3855.pdf

Parameters:
  • pauli_word (tuple) – Openfermion-like tuple that generates a pauli_word to exponentiate

  • coef (float) – The coefficient in the exponentiation

  • variational (bool) – When creating the Gate objects, label the (controlled-)Rz gate as variational

  • control (integer) – The control qubit label

Returns:

list – list of Gate objects that represents the exponentiation of the pauli word.

tangelo.toolboxes.ansatz_generator.ansatz_utils.get_exponentiated_qubit_operator_circuit(qubit_op, time=1.0, variational=False, trotter_order=1, control=None, return_phase=False, pauli_order=None)

Generate the exponentiation of a qubit operator in first- or second-order Trotterized form. The algorithm is described in Whitfield 2010 https://arxiv.org/pdf/1001.3855.pdf

Parameters:
  • qubit_op (QubitOperator) – qubit hamiltonian to exponentiate

  • time (float or dict) – The time to evolve the whole system or individiual times for each term in the operator. If a dictionary, must have keys that have a matching key in qubit_op.terms

  • variational (bool) – Whether the coefficients are variational

  • trotter_order (int) – order of trotter approximation, only 1 or 2 are supported.

  • return_phase (bool) – Return the global-phase generated

  • pauli_order (list) – The desired pauli_word order for trotterization defined as a list of (pauli_word, coeff) elements which have matching dictionary elements pauli_word: coeff in QubitOperator terms.items(). The coeff in pauli_order is used to generate the exponential.

Returns:
  • Circuit – circuit corresponding to exponentiation of qubit operator

  • phase – The global phase of the time evolution if return_phase=True else not included

tangelo.toolboxes.ansatz_generator.ansatz_utils.get_qft_circuit(qubits, n_qubits=None, inverse=False, swap=True)

Returns the QFT or iQFT circuit given a list of qubits to act on.

Parameters:
  • qubits (int or list) – The list of qubits to apply the QFT circuit to. If an integer, the operation is applied to the [0,…,qubits-1] qubits

  • n_qubits – Argument to initialize a Circuit with the desired number of qubits.

  • inverse (bool) – If True, the inverse QFT is applied. If False, QFT is applied

  • swap (bool) – Whether to apply swap to the registers.

  • Returns – Circuit: The circuit that applies QFT or iQFT to qubits

tangelo.toolboxes.ansatz_generator.ansatz_utils.givens_gate(target, theta, is_variational=False)

Generates the list of gates corresponding to a givens rotation exp(-theta*(XX+YY))

Explicitly the two-qubit matrix is [[1, 0, 0, 0],

[0, cos(theta), -sin(theta), 0], [0, sin(theta), cos(theta), 0], [0, 0, 0, 1]]

Parameters:
  • target (list) – list of two integers that indicate which qubits are involved in the givens rotation

  • theta (float) – the rotation angle

  • is_variational (bool) – Whether the rotation angle is a variational parameter.

Returns:

list of Gate – The list of gates corresponding to the givens rotation

tangelo.toolboxes.ansatz_generator.ansatz_utils.pauli_op_to_gate(index, op, inverse=False)

Return the change-of-basis gates required to map pauli words to quantum circuit as per Whitfield 2010 (https://arxiv.org/pdf/1001.3855.pdf).

tangelo.toolboxes.ansatz_generator.ansatz_utils.recursive_trotter_suzuki_decomposition(pauli_words, order, time)

Recursive function that returns the Trotter-Suzuki decomposition as defined in https://arxiv.org/pdf/math-ph/0506007.pdf

Parameters:
  • pauli_words (List[tuple]) – The list of Pauli (terms, coeff) to perform the Trotter-Suzuki decomposition to the given order.

  • order (int) – The order of the decomposition

  • time (float) – The evolve time applied equally to all terms.

Returns:

List[tuple] – The list of (pauli, coeff) that defines the gate sequence for time-evolution.

tangelo.toolboxes.ansatz_generator.ansatz_utils.swap_registers(gate_list, qubit_list)

Function to swap register order. :param gate_list: List of Gate :type gate_list: list :param qubit_list: List of integers for the locations of the qubits :type qubit_list: list

Result:

list: The Gate operations that swap the register order

tangelo.toolboxes.ansatz_generator.ansatz_utils.trotterize(operator, time=1.0, n_trotter_steps=1, trotter_order=1, variational=False, mapping_options={}, control=None, return_phase=False)

Generate the circuit that represents time evolution of an operator. This circuit is generated as a trotterization of a qubit operator which is either the input or mapped from the given fermion operator.

Parameters:
  • operator (QubitOperator or FermionOperator) – operator to time evolve

  • time (float or dict) – The time to evolve the whole system or individiual times for each term in the operator. If a dict, each key must match the keys in operator.terms

  • variational (bool) – whether the coefficients are variational

  • trotter_order (int) – order of trotter approximation, 1 or 2 supported

  • n_trotter_steps (int) – The number of different time steps taken for total time t

  • mapping_options (dict) –

    Defines the desired Fermion->Qubit mapping Default values:{“up_then_down”: False, “qubit_mapping”: “jw”, “n_spinorbitals”: None,

    ”n_electrons”: None}

  • control (int) – The label for the control Qubit of the time-evolution

  • return_phase (bool) – If return_phase is True, the global phase of the time-evolution will be returned

Returns:
  • Circuit – circuit corresponding to time evolution of the operator

  • float – the global phase not included in the circuit if return_phase=True else not included

tangelo.toolboxes.ansatz_generator.fermionic_operators module

This module defines the fermionic operators that can be used to obtain expectation values of commonly used quantum numbers. The available operators are 1) N: number of electrons 2) Sz: The spin z-projection Sz|psi>=m_s|psi> 3) S^2: The spin quantum number S^2|psi>=s(s+1)|psi> associated with spin angular momentum which allows one to decide whether the state has the correct properties.

tangelo.toolboxes.ansatz_generator.fermionic_operators.number_operator(n_orbs, up_then_down=False)

Function to generate the normal ordered number operator as a FermionOperator.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • up_then_down – The ordering of the spin orbitals. qiskit (True) openfermion (False).

Returns:

FermionOperator – The number operator penalty hat{N}.

tangelo.toolboxes.ansatz_generator.fermionic_operators.number_operator_list(n_orbs, up_then_down=False)

Function to generate the normal ordered number operator as a list.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • up_then_down (bool) – The ordering of the spin orbitals. qiskit (True) openfermion (False).

Returns:

list – The number operator penalty hat{N}.

tangelo.toolboxes.ansatz_generator.fermionic_operators.spin2_operator(n_orbs, up_then_down=False)

Function to generate the normal ordered S^2 operator as a FermionOperator.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • up_then_down (bool) – The ordering of the spin orbitals. qiskit (True) openfermion (False).

Returns:

FermionOperator – The S^2 operator hat{S}^2.

tangelo.toolboxes.ansatz_generator.fermionic_operators.spin2_operator_list(n_orbs, up_then_down=False)

Function to generate the normal ordered S^2 operator as a list.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • up_then_down (bool) – The ordering of the spin orbitals. qiskit (True) openfermion (False).

Returns:

list – The S^2 operator hat{S}^2.

tangelo.toolboxes.ansatz_generator.fermionic_operators.spinz_operator(n_orbs, up_then_down=False)

Function to generate the normal ordered Sz operator.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • up_then_down (bool) – The ordering of the spin orbitals. qiskit (True) openfermion (False).

Returns:

FermionOperator – The Sz operator hat{Sz}.

tangelo.toolboxes.ansatz_generator.fermionic_operators.spinz_operator_list(n_orbs, up_then_down=False)

Function to generate the normal ordered Sz operator as a list.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • up_then_down (bool) – The ordering of the spin orbitals. qiskit (True) openfermion (False).

Returns:

list – The Sz operator hat{Sz}.

tangelo.toolboxes.ansatz_generator.hea module

This module defines the hardware efficient ansatz class, for use in applying VQE as first defined in “Hardware-efficient Variational Quantum Eigensolver for Small Molecules and Quantum Magnets” https://arxiv.org/abs/1704.05018.

class tangelo.toolboxes.ansatz_generator.hea.HEA(molecule=None, mapping='jw', up_then_down=False, n_layers=2, rot_type='euler', n_qubits=None, n_electrons=None, spin=None, reference_state='HF')

Bases: Ansatz

This class implements the HEA ansatz. A molecule or a number of qubits + a number of electrons can be passed to this class.

Parameters:
  • molecule (SecondQuantizedMolecule) – The molecular system.

  • mapping (str) – one of the supported qubit mapping identifiers. Default: “JW”

  • up_then_down (bool) – change basis ordering putting all spin up orbitals first, followed by all spin down. Default, False has alternating spin up/down ordering.

  • n_layers (int) – The number of HEA ansatz layers to use. One layer is hea_rot_type + grid of CNots. Default: 2.

  • rot_type (str) – “euler”: RzRxRz on each qubit for each rotation layer. “real”: Ry on each qubit for each rotation layer. Default: “euler”.

  • n_qubits (int) – The number of qubits in the ansatz. Default, None.

  • n_electrons (int) – Self-explanatory.

  • reference_state (str, Circuit) – “HF”: Hartree-Fock reference state. “zero”: for no reference state. Can also be a Circuit object, in which case a copy of circuit with variational parameters fixed is used. Default: “HF”.

build_circuit(var_params=None)

Construct the variational circuit to be used as our ansatz.

prepare_reference_state()

Prepare a circuit generating the HF reference state.

set_var_params(var_params=None)

Set values for variational parameters, such as zeros, random numbers, MP2 (…), providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Update variational parameters (done repeatedly during VQE).

tangelo.toolboxes.ansatz_generator.ilc module

This module defines the qubit coupled cluster ansatz class with involutory linear combinations (ILC) of anticommuting sets (ACS) of Pauli words (generators). Relative to the direct interation set (DIS) of QCC generators, which incur an exponential growth of Hamiltonian terms upon dressing, the ACS of ILC generators enables Hamiltonian dressing such that the number of terms grows quadratically and exact quadratic truncation of the Baker-Campbell-Hausdorff expansion. For more information about this ansatz, see references below.

Refs:
      1. Lang, I. G. Ryabinkin, and A. F. Izmaylov.

    arXiv:2002.05701v1, 2020, 1–10.

      1. Lang, I. G. Ryabinkin, and A. F. Izmaylov.

    1. Chem. Theory Comput. 2021, 17, 1, 66–78.

class tangelo.toolboxes.ansatz_generator.ilc.ILC(molecule, mapping='jw', up_then_down=False, acs=None, qmf_circuit=None, qmf_var_params=None, qubit_ham=None, ilc_tau_guess=0.01, deilc_dtau_thresh=0.001, max_ilc_gens=None, reference_state='HF')

Bases: Ansatz

This class implements the ILC ansatz. Closed-shell and restricted open-shell ILC are supported. While the form of the ILC ansatz is the same for either variation, the underlying fermionic mean-field state is treated differently depending on the spin. Closed-shell or restricted open-shell ILC implies that spin = 0 or spin != 0 and the fermionic mean-field state is obtained using a RHF or ROHF Hamiltonian, respectively.

Parameters:
  • molecule (SecondQuantizedMolecule or dict) – The molecular system, which can be passed as a SecondQuantizedMolecule or a dictionary with keys that specify n_spinoribtals, n_electrons, and spin. Default, None.

  • mapping (str) – One of the supported mapping identifiers. Default, “jw”.

  • up_then_down (bool) – Change basis ordering putting all spin-up orbitals first, followed by all spin-down. Default, False.

  • acs (list of QubitOperator) – The mutually anticommuting generator list for the ILC ansatz. Default, None.

  • qmf_circuit (Circuit) – An instance of tangelo.linq Circuit class implementing a QMF state circuit. If passed from the QMF ansatz class, parameters are variational. If None, one is created with QMF parameters that are not variational. Default, None.

  • qmf_var_params (list or numpy array of float) – QMF variational parameter set. If None, the values are determined using a Hartree-Fock reference state. Default, None.

  • qubit_ham (QubitOperator) – Pass a qubit Hamiltonian to the ansatz class and ignore the fermionic Hamiltonian in molecule. Default, None.

  • deilc_dtau_thresh (float) – Threshold for |dEILC/dtau| so that a candidate group is added to the DIS if |dEILC/dtau| >= deilc_dtau_thresh for a generator. Default, 1e-3 a.u.

  • ilc_tau_guess (float) – The initial guess for all ILC variational parameters. Default, 1e-2 a.u.

  • max_ilc_gens (int or None) – Maximum number of generators allowed in the ansatz. If None, one generator from each DIS group is selected. If int, then min(|DIS|, max_ilc_gens) generators are selected in order of decreasing |dEILC/dtau|. Default, None.

  • reference_state (string, Circuit) – The reference state id for the ansatz. If a Circuit object is passed, then a copy of this circuit overrides the qmf_circuit and its variational parameters override qmf_var_params. The supported string reference states are stored in the supported_reference_state attributes. Default, “HF”.

build_circuit(var_params=None)

Build and return the quantum circuit implementing the state preparation ansatz (with currently specified initial_state and var_params).

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g prepare reference wavefunction with HF, multi-reference state, etc). These preparations must be consistent with the transform used to obtain the qubit operator.

set_var_params(var_params=None)

Set values for variational parameters, such as zeros or floats, providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Shortcut: set value of variational parameters in the existing ansatz circuit member. Preferable to rebuilding your circuit from scratch, which can be an involved process.

tangelo.toolboxes.ansatz_generator.penalty_terms module

This module defines the penatly terms that can be added to the target fermionic Hamiltonian, providing the ability to restrict the Hilbert space of solutions using VQE. For example usages see

  • Illa G. Ryabinkin, Scott N. Genin, Artur F. Izmaylov. “Constrained

    variational quantum eigensolver: Quantum computer search engine in the Fock space” https://arxiv.org/abs/1806.00461.

  • Gabriel Greene-Diniz, David Munoz Ramo. “Generalized unitary coupled

    cluster excitations for multireference molecular states optimized by the Variational Quantum Eigensolver” https://arxiv.org/abs/1910.05168.

tangelo.toolboxes.ansatz_generator.penalty_terms.combined_penalty(n_orbs, opt_penalty_terms=None, up_then_down=False)

Function to generate the sum of all available penalty terms, currently implemented are - “N”: number operator with eigenvalue (number of particles). - “Sz”: Sz|s,m_s> = ms|s,m_s>. - “S^2”: S^2|s,m_s> = s(s+1)|s,m_s>.

Parameters:
  • n_orbs (int) – number of active orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • opt_penalty_terms (dict) –

    The options for each penalty “N”, “Sz”, “S^2” as - “N” (array or list[float]):

    [Prefactor, Value] Prefactor * (hat{N} - Value)^2

    • ”Sz” (array or list[float]):

      [Prefactor, Value] Prefactor * (hat{Sz} - Value)^2

    • ”S^2” (array or list[float]):

      [Prefactor, Value] Prefactor * (hat{S}^2 - Value)^2

  • up_then_down – The ordering of the spin orbitals. qiskit (True) openfermion (False) If later transforming to qubits, one should generally let the qubit mapping handle this.

Returns:

FermionOperator – The combined n_electron+sz+s^2 penalty terms.

tangelo.toolboxes.ansatz_generator.penalty_terms.number_operator_penalty(n_orbs, n_electrons, mu=1, up_then_down=False)

Function to generate the normal ordered number operator penalty term as a FermionOperator.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • n_electrons (int) – number of electrons.

  • mu (float) – Positive number in front of penalty term.

  • up_then_down (bool) – The ordering of the spin orbitals. qiskit (True) openfermion (False) If later transforming to qubits, one should generally let the qubit mapping handle the ordering.

Returns:

FermionOperator – The number operator penalty term mu*(hat{N}-n_electrons)^2.

tangelo.toolboxes.ansatz_generator.penalty_terms.spin2_operator_penalty(n_orbs, s2, mu=1, up_then_down=False)

Function to generate the normal ordered S^2 operator penalty term, operator form taken from https://pubs.rsc.org/en/content/articlepdf/2019/cp/c9cp02546d.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • s2 (int) – the desired S^2 quantum number to penalize for. singlet: s2=0*(0+1)=0, doublet: s2=(1/2)*(1/2+1)=3/4, triplet, s2=1*(1+1)=2 …

  • mu (float) – Positive number in front of penalty term.

  • up_then_down – The ordering of the spin orbitals. qiskit (True) openfermion (False) If later transforming to qubits, one should generally let the qubit mapping handle the ordering.

Returns:

FermionOperator – The S^2 operator penalty term mu*(hat{S}^2-s2)^2.

tangelo.toolboxes.ansatz_generator.penalty_terms.spin_operator_penalty(n_orbs, sz, mu=1, up_then_down=False)

Function to generate the normal ordered Sz operator penalty term.

Parameters:
  • n_orbs (int) – number of orbitals in the fermion basis (this is number of spin-orbitals divided by 2).

  • sz (int) – the desired Sz quantum number to penalize for.

  • mu (float) – Positive number in front of penalty term.

  • up_then_down – The ordering of the spin orbitals. qiskit (True) openfermion (False) If later transforming to qubits, one should generally let the qubit mapping handle the ordering.

Returns:

FermionOperator – The Sz operator penalty term mu*(hat{Sz}-sz)^2.

tangelo.toolboxes.ansatz_generator.puccd module

This module defines the pUCCD ansatz class. The molecular FermionOperator is expected to be converted to a BosonOperator (electrons in pairs). Single bosonic excitations (corresponding to double fermion excitations) form the ansatz. Those excitations are transformed into a quantum circuit via Givens rotations.

Ref:
  • V.E. Elfving, M. Millaruelo, J.A. Gámez, and C. Gogolin.

    Phys. Rev. A 103, 032605 (2021).

class tangelo.toolboxes.ansatz_generator.puccd.pUCCD(molecule, reference_state='HF')

Bases: Ansatz

This class implements the pUCCD ansatz, as described in Phys. Rev. A 103, 032605 (2021). Electrons are described as hard-core boson and only double excitations are considered.

Parameters:
  • molecule (SecondQuantizedMolecule) – Self-explanatory.

  • reference_state (string, Circuit) – String refering to an initial state. Can also be a Circuit object, in which case a copy of circuit with variational parameters fixed is used. Default: “HF”.

build_circuit(var_params=None)

Build and return the quantum circuit implementing the state preparation ansatz (with currently specified initial_state and var_params).

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g prepare reference wavefunction with HF, multi-reference state, etc). These preparations must be consistent with the transform used to obtain the qubit operator.

set_var_params(var_params=None)

Set values for variational parameters, such as ones, zeros or random numbers providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Shortcut: set value of variational parameters in the already-built ansatz circuit member. Preferable to rebuilt your circuit from scratch, which can be an involved process.

tangelo.toolboxes.ansatz_generator.qcc module

This module defines the qubit coupled cluster (QCC) ansatz class. The motivation behind this ansatz is to provide an improved alternative to classical unitary coupled cluster for describing the electron correlation of molecular systems. This implementation is based on Ref. 1, where the ansaztz takes the form of a variational product state built directly from a set of parameterized exponentiated qubit operators. A qubit operator is selected for the ansatz based on an energy gradient criterion that indicates its potential contribution to variational lowering of the QCC energy. For chemical applications, the quantum mean-field ansatz is used in conjunction with this ansatz to describe an electronic wave function on a quantum computer. For more information about this ansatz and its variations, see references below.

Refs:
      1. Ryabinkin, T.-C. Yen, S. N. Genin, and A. F. Izmaylov.

    1. Chem. Theory Comput. 2018, 14 (12), 6317-6326.

      1. Ryabinkin, R. A. Lang, S. N. Genin, and A. F. Izmaylov.

    1. Chem. Theory Comput. 2020, 16, 2, 1055–1063.

      1. Lang, I. G. Ryabinkin, and A. F. Izmaylov.

    1. Chem. Theory Comput. 2021, 17, 1, 66–78.

class tangelo.toolboxes.ansatz_generator.qcc.QCC(molecule, mapping='jw', up_then_down=False, dis=None, qmf_circuit=None, qmf_var_params=None, qubit_ham=None, qcc_tau_guess=0.01, deqcc_dtau_thresh=0.001, max_qcc_gens=None, reference_state='HF')

Bases: Ansatz

This class implements the QCC ansatz. Closed-shell and restricted open-shell QCC are supported. While the form of the QCC ansatz is the same for either variation, the underlying fermionic mean-field state is treated differently depending on the spin. Closed-shell or restricted open-shell QCC implies that spin = 0 or spin != 0 and the fermionic mean-field state is obtained using a RHF or ROHF Hamiltonian, respectively.

Parameters:
  • molecule (SecondQuantizedMolecule, SecondQuantizedDMETFragment or dict) – The molecular system, which can be passed as a SecondQuantizedMolecule/SecondQuantizedDMETFragment or a dictionary with keys that specify n_spinoribtals, n_electrons, and spin. Default, None.

  • mapping (str) – One of the supported qubit mapping identifiers. Default, “jw”.

  • up_then_down (bool) – Change basis ordering putting all spin-up orbitals first, followed by all spin-down. Default, False.

  • dis (list of QubitOperator) – The direct interaction set (DIS) of generators for the QCC ansatz. Default, None.

  • qmf_circuit (Circuit) – An instance of tangelo.linq Circuit class implementing a QMF state circuit. If passed from the QMF ansatz class, parameters are variational. If None, one is created with QMF parameters that are not variational. Default, None.

  • qmf_var_params (list or numpy array of float) – QMF variational parameter set. If None, the values are determined using a Hartree-Fock reference state. Default, None.

  • qubit_ham (QubitOperator) – Pass a qubit Hamiltonian to the QCC ansatz class and ignore the fermionic Hamiltonian in molecule. Default, None.

  • deqcc_dtau_thresh (float) – Threshold for |dEQCC/dtau| so that a candidate group is added to the DIS if |dEQCC/dtau| >= deqcc_dtau_thresh for a generator. Default, 1e-3 a.u.

  • qcc_tau_guess (float) – The initial guess for all QCC variational parameters. Default, 1e-2 a.u.

  • max_qcc_gens (int or None) – Maximum number of generators allowed in the ansatz. If None, one generator from each DIS group is selected. If int, then min(|DIS|, max_qcc_gens) generators are selected in order of decreasing |dEQCC/dtau|. Default, None.

  • reference_state (string) – The reference state id for the ansatz. If a Circuit object is passed, then a copy of this circuit overrides the qmf_circuit and its variational parameters override qmf_var_params. The supported reference states are stored in the supported_reference_state attributes. Default, “HF”.

build_circuit(var_params=None)

Build and return the quantum circuit implementing the state preparation ansatz (with currently specified initial_state and var_params).

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g prepare reference wavefunction with HF, multi-reference state, etc). These preparations must be consistent with the transform used to obtain the qubit operator.

set_var_params(var_params=None)

Set values for variational parameters, such as zeros or floats, providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Shortcut: set value of variational parameters in the existing ansatz circuit member. Preferable to rebuilding your circuit from scratch, which can be an involved process.

tangelo.toolboxes.ansatz_generator.qmf module

This module defines the qubit mean-field (QMF) ansatz class. The ansatz is a variational product state built from a set of parameterized single-qubit states. For applications in quantum chemistry, the ansatz can be used to describe the mean-field component of an electronic wave function on a quantum computer. For more information about this ansatz, see references below.

Refs:
      1. Ryabinkin, T.-C. Yen, S. N. Genin, and A. F. Izmaylov.

    1. Chem. Theory Comput. 2018, 14 (12), 6317-6326.

      1. Ryabinkin and S. N. Genin.

    1. N. Genin, I. G. Ryabinkin, and A. F. Izmaylov. https://arxiv.org/abs/1901.04715 2019.

      1. Ryabinkin, S. N. Genin, and A. F. Izmaylov.

    1. Chem. Theory Comput. 2019, 15, 1, 249–255.

class tangelo.toolboxes.ansatz_generator.qmf.QMF(molecule, mapping='jw', up_then_down=False, init_qmf=None, reference_state='HF')

Bases: Ansatz

This class implements the QMF ansatz. Closed-shell and restricted open-shell QMF are supported. While the form of the QMF ansatz is the same for either variation, the underlying fermionic mean-field state is treated differently depending on the spin. Closed-shell or restricted open-shell QMF implies that spin = 0 or spin != 0 and the fermionic mean-field state is obtained using a RHF or ROHF Hamiltonian, respectively.

Optimizing QMF variational parameters can be risky without taking proper precautions, especially when a random initial guess is used. It is recommended that penalty terms are added to the mean-field Hamiltonian to enforce appropriate electron number and spin angular momentum symmetries on the QMF wave function during optimization (see Ref. 4). If using penalty terms is to be avoided, an initial guess based on a Hartree-Fock reference state will likely converge quickly to the desired state, but this is not guaranteed.

Parameters:
  • molecule (SecondQuantizedMolecule) – The molecular system.

  • mapping (str) – One of the supported qubit mapping identifiers. Default, “jw”.

  • up_then_down (bool) – Change basis ordering putting all spin up orbitals first, followed by all spin down. Default, False.

  • init_qmf (dict) – Controls for QMF variational parameter initialization and mean-field Hamiltonian penalization. Supported keys are “init_params”, “N”, “S^2”, or “Sz” (str). Values of “init_params” must be in self.supported_initial_var_params (str). Values of “N”, “S^2”, or “Sz” are (tuple or None). If tuple, the elements are a penalty term coefficient, mu (float), and a target value of the penalty operator (int). Example - “key”: (mu, target). If “N”, “S^2”, or “Sz” is None, a penalty term is added with default mu and target values: mu = 1.5 and target is derived from molecule as <N> = n_electrons, <S^2> = spin_z * (spin_z + 1), and <Sz> = spin_z, where spin_z = spin // 2. Key, value pairs are case sensitive and mu > 0. Default, {“init_params”: “hf_state”}.

  • reference_state (string, Circuit) – The reference state id for the ansatz. Can also be a Circuit object, in which case a copy of circuit with variational parameters fixed is used. The supported reference states are stored in the supported_reference_state attributes. Default, “HF”.

build_circuit(var_params=None)

Build and return the quantum circuit implementing the state preparation ansatz (with currently specified initial_state and var_params).

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g prepare reference wavefunction with HF, multi-reference state, etc). These preparations must be consistent with the transform used to obtain the qubit operator.

set_var_params(var_params=None)

Set values for variational parameters, such as zeros, random numbers, or a Hartree-Fock state occupation vector, providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Shortcut: set value of variational parameters in the already-built ansatz circuit member. Preferable to rebuilt your circuit from scratch, which can be an involved process.

tangelo.toolboxes.ansatz_generator.rucc module

This module defines the reduced UCCs ansatz class (RUCC, refering to both UCC1 and UCC3), providing the foundation to implement variational ansatz circuits. They are UCCD and UCCSD ansatz, but terms acting in the same way on an Hartree-Fock initial state have been removed.

This must be used on a 2 levels system (2 MOs, 4 SOs) to be physically relevant.

Reference for those circuits.
class tangelo.toolboxes.ansatz_generator.rucc.RUCC(n_var_params=1)

Bases: Ansatz

This class implements the reduced-UCC ansatz, i.e. UCC1=UCCD and UCC3=UCCSD. Currently, only closed-shell is supported. This implies that the mean-field is computed with the RHF reference integrals.

Parameters:

n_var_params (int) – Number of variational parameters, must be 1 or 3.

build_circuit(var_params=None)

Build and return the quantum circuit implementing the state preparation ansatz (with currently specified initial_state and var_params).

Parameters:

list – Initial variational parameters. Must be consistent with the chosen UCC (1 or 3).

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g. prepare reference wavefunction with HF, multi-reference state, etc). This method outputs |1010>.

Returns:

Circuit|1010> initial state.

set_var_params(var_params=None)

Set values for variational parameters, such as zeros, random numbers providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Shortcut: set value of variational parameters in the already-built ansatz circuit member. The circuit does not need to be rebuilt every time if only the variational parameters change.

Parameters:

list – Variational parameters to parse into the circuit.

tangelo.toolboxes.ansatz_generator.uccgd module

This module defines the UCCGD ansatz class. It provides a chemically inspired ansatz and is an implementation of the classical unitary CCGD ansatz. Generalized double excitation determinants, in accordance with the system number of electron and spin, are considered. For more information about this ansatz, see references below.

Refs:

class tangelo.toolboxes.ansatz_generator.uccgd.UCCGD(molecule, mapping='JW', up_then_down=False, reference_state='HF')

Bases: Ansatz

This class implements the UCCGD ansatz. This implies that the mean-field is computed with the RHF or ROHF reference integrals.

Parameters:
  • molecule (SecondQuantizedMolecule) – The molecular system.

  • mapping (str) – one of the supported qubit mapping identifiers. Default: “JW”.

  • up_then_down (bool) – change basis ordering putting all spin up orbitals first, followed by all spin down. Default, False (i.e. has alternating spin up/down ordering).

  • reference_state (string, Circuit) – The reference state id for the ansatz. The supported reference states are stored in the supported_reference_state attributes. Can also be a Circuit object, in which case a copy of circuit with variational parameters fixed is used. Default: “HF”.

build_circuit(var_params=None)

Build and return the quantum circuit implementing the state preparation ansatz (with currently specified initial_state and var_params).

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g prepare reference wavefunction with HF, multi-reference state, etc). These preparations must be consistent with the transform used to obtain the qubit operator.

set_var_params(var_params=None)

Set values for variational parameters, such as zeros, random numbers, providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Shortcut: set value of variational parameters in the already-built ansatz circuit member. Preferable to rebuilt your circuit from scratch, which can be an involved process.

tangelo.toolboxes.ansatz_generator.uccsd module

This module defines the UCCSD ansatz class. It provides a chemically inspired ansatz and is an implementation of the classical unitary CCSD ansatz. Single and double excitation determinants, in accordance with the system number of electron and spin, are considered. For more information about this ansatz, see references below.

Refs:
  • P.Kl. Barkoutsos, J.F. Gonthier, I. Sokolov, N. Moll, G. Salis, A. Fuhrer,

    M. Ganzhorn, D.J. Egger, M. Troyer, A. Mezzacapo, S. Filipp, and I. Tavernelli. Phys. Rev. A 98, 022322 (2018).

  • I.O. Sokolov, P.Kl. Barkoutsos, P.J. Ollitrault, D. Greenberg, J. Rice,
    1. Pistoia, and I. Tavernelli. J. Chem. Phys. 152, 124107 (2020).

    1. Shen, X. Zhang, S. Zhang, J.N. Zhang, M.H. Yung, and K. Kim.

    Physical Review A 95, 020501 (2017).

class tangelo.toolboxes.ansatz_generator.uccsd.UCCSD(molecule, mapping='JW', up_then_down=False, spin=None, reference_state='HF')

Bases: Ansatz

This class implements the UCCSD ansatz. Currently, closed-shell and restricted open-shell UCCSD are supported. This implies that the mean-field is computed with the RHF or ROHF reference integrals.

Parameters:
  • molecule (SecondQuantizedMolecule) – The molecular system.

  • mapping (str) – one of the supported qubit mapping identifiers. Default, “jw”.

  • up_then_down (bool) – change basis ordering putting all spin up orbitals first, followed by all spin down. Default, False (i.e. has alternating spin up/down ordering).

  • reference_state (string, Circuit) – The reference state id for the ansatz. Can also be a Circuit object, in which case a copy of circuit with variational parameters fixed is used. The supported string reference states are stored in the supported_reference_state attributes. Default, “HF”.

build_circuit(var_params=None)

Build and return the quantum circuit implementing the state preparation ansatz (with currently specified initial_state and var_params).

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g prepare reference wavefunction with HF, multi-reference state, etc). These preparations must be consistent with the transform used to obtain the qubit operator.

set_var_params(var_params=None)

Set values for variational parameters, such as zeros, random numbers, MP2 (…), providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Shortcut: set value of variational parameters in the already-built ansatz circuit member. Preferable to rebuilt your circuit from scratch, which can be an involved process.

tangelo.toolboxes.ansatz_generator.upccgsd module

This module defines the k-UpCCGSD ansatz class. It provides a chemically inspired ansatz and is an implementation of the classical unitary CCGSD ansatz. Generalized Single and pairwise double excitation determinants, in accordance with the system number of electron and spin, are considered. For more information about this ansatz, see references below.

Refs:
  • Joonho Lee, William J. Huggins, Martin Head-Gordon, and K. Birgitta.

    “Generalized Unitary Couple Cluster Wavefunctions for Quantum Computation” arxiv:1810.02327.

class tangelo.toolboxes.ansatz_generator.upccgsd.UpCCGSD(molecule, mapping='JW', up_then_down=False, k=2, reference_state='HF')

Bases: Ansatz

This class implements the UpCCGSD ansatz. This implies that the mean-field is computed with the RHF or ROHF reference integrals.

Parameters:
  • molecule (SecondQuantizedMolecule) – The molecular system.

  • k – parameters for the number of times UpCCGSD is repeated see (arxiv:1810.02327) for details. Default, 2.

  • mapping (str) – one of the supported qubit mapping identifiers. Default: “JW”.

  • up_then_down (bool) – change basis ordering putting all spin up orbitals first, followed by all spin down. Default, False (i.e. has alternating spin up/down ordering).

  • reference_state (string, Circuit) – The reference state id for the ansatz. The supported string reference states are stored in the supported_reference_state attributes. Can also be a Circuit object, in which case a copy of circuit with variational parameters fixed is used. Default: “HF”.

build_circuit(var_params=None)

Build and return the quantum circuit implementing the state preparation ansatz (with currently specified initial_state and var_params).

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g prepare reference wavefunction with HF, multi-reference state, etc). These preparations must be consistent with the transform used to obtain the qubit operator.

set_var_params(var_params=None)

Set values for variational parameters, such as zeros, random numbers, providing some keywords for users, and also supporting direct user input (list or numpy array). Return the parameters so that workflows such as VQE can retrieve these values.

update_var_params(var_params)

Shortcut: set value of variational parameters in the already-built ansatz circuit member. Preferable to rebuilt your circuit from scratch, which can be an involved process.

tangelo.toolboxes.ansatz_generator.variational_circuit module

This module defines an ansatz class to wrap up a custom tangelo.linq circuit.

class tangelo.toolboxes.ansatz_generator.variational_circuit.VariationalCircuitAnsatz(abstract_circuit)

Bases: Ansatz

This class takes an arbitrary circuit and convert it to an Ansatz. This enables users to provide a custom pre-built circuit.

Parameters:

Circuit – Circuit with variational gates.

build_circuit(var_params=None)

Update parameters of the pre-built circuit.

prepare_reference_state()

Method not needed as it is expected to be in the circuit provided.

set_var_params(var_params=None)

Set initial variational parameter values. Defaults to random.

update_var_params(var_params)

Update variational parameters (done repeatedly during VQE).

tangelo.toolboxes.ansatz_generator.vsqs module

This module defines the Variationally Scheduled Quantum Simulation class. It provides an Adiabatic State Preparation (ASP) inspired ansatz as described in https://arxiv.org/abs/2003.09913.

class tangelo.toolboxes.ansatz_generator.vsqs.VSQS(molecule=None, mapping='jw', up_then_down=False, intervals=2, time=1.0, qubit_hamiltonian=None, reference_state=None, h_init=None, h_nav=None, trotter_order=1)

Bases: Ansatz

This class implements the Variationally Scheduled Quantum Simulator (VSQS) for state preparation as described in https://arxiv.org/abs/2003.09913

Must supply either a molecule or a qubit_hamiltonian. If supplying a qubit_hamiltonian, must also supply a reference_state Circuit and a h_init QubitOperator.

Parameters:
  • molecule (SecondQuantizedMolecule) – The molecular system. Default: None

  • mapping (str) – One of the supported fermion to qubit mappings. Default : “JW”

  • up_then_down (bool) – Change basis ordering, putting all spin up orbitals first, followed by all spin down. Default: False (alternating spin up/down ordering)

  • intervals (int) – The number of steps in the VSQS process. Must be greater than 1. Default: 2

  • time (float) – The propagation time. Default: 1.

  • qubit_hamiltonian (QubitOperator) – The qubit Hamiltonian to evolve. Default: None

  • reference_state (Circuit) – The reference state for the propagation as defined by a Circuit. Mandatory if supplying a qubit_hamiltonian. Default: None

  • h_init (QubitOperator) – The initial qubit Hamiltonian that corresponds to the reference state. Mandatory if supplying a qubit_hamiltonian. Default: None

  • h_nav (QubitOperator) – The navigator Hamiltonian. Default: None

  • trotter_order (int) – The order of the Trotterization for each qubit operator. Default: 1

build_circuit(var_params=None)

Build the VSQS circuit by successive first- or second-order trotterizations of h_init, h_final and possibly h_nav

prepare_reference_state()

Prepare a circuit generating the HF reference state.

set_var_params(var_params=None)

Set values for the variational parameters. Default is linear interpolation.

update_var_params(var_params)

Update the variational parameters in the circuit without rebuilding.

Module contents