qxmt.ansatze.pennylane package#

Submodules#

Module contents#

class qxmt.ansatze.pennylane.UCCSDAnsatz(device, hamiltonian)#

Bases: BaseVQEAnsatz

Unitary Coupled-Cluster Singles and Doubles (UCCSD) ansatz.

This class implements the UCCSD ansatz for quantum chemistry calculations. UCCSD is a popular ansatz for quantum chemistry that includes single and double excitations from the Hartree-Fock reference state.

Parameters:
  • device (BaseDevice) – Quantum device to use for the ansatz.

  • hamiltonian (MolecularHamiltonian) – Molecular Hamiltonian to use for the ansatz.

wires#

List of qubit indices used in the circuit.

hf_state#

Hartree-Fock reference state.

singles#

List of single excitation indices.

doubles#

List of double excitation indices.

s_wires#

List of wire indices for single excitations.

d_wires#

List of wire indices for double excitations.

Example

>>> from qxmt.devices.pennylane import DefaultQubit
>>> from qxmt.hamiltonians.pennylane.molecular import MolecularHamiltonian
>>> device = DefaultQubit(n_qubits=4)
>>> hamiltonian = MolecularHamiltonian(...)
>>> ansatz = UCCSDAnsatz(device, hamiltonian)
>>> params = np.random.rand(10)  # Number of parameters depends on the system
>>> ansatz.circuit(params)

Note

The number of parameters required depends on the number of single and double excitations, which is determined by the number of electrons and orbitals in the system.

URL: https://docs.pennylane.ai/en/stable/code/api/pennylane.UCCSD.html

circuit(params)#

Construct the UCCSD quantum circuit.

Parameters:

params (np.ndarray) – Parameters for the UCCSD circuit. The length of this array should match the number of single and double excitations.

Return type:

None

Note

The UCCSD operation includes both single and double excitations from the Hartree-Fock reference state.

prepare_excitation_wires()#

Prepare the excitation wires for single and double excitations.

This method: 1. Generates all possible single and double excitations from the Hartree-Fock state 2. Converts these excitations to wire indices that can be used in the quantum circuit

The results are stored in the following attributes: - self.singles: List of single excitation indices - self.doubles: List of double excitation indices - self.s_wires: List of wire indices for single excitations - self.d_wires: List of wire indices for double excitations

Note

The number of excitations depends on the number of electrons and orbitals in the system.

Return type:

None

prepare_hf_state()#

Prepare the Hartree-Fock reference state.

This method creates the Hartree-Fock reference state using PennyLane’s qchem module. The Hartree-Fock state is a product state where the first n electrons occupy the lowest energy orbitals.

The state is stored in self.hf_state as a numpy array.

Note

The number of electrons and orbitals are obtained from the Hamiltonian.

Return type:

None