uniqc.algorithmics.circuits.vqd module#

Variational Quantum Deflation (VQD) circuit components.

uniqc.algorithmics.circuits.vqd.vqd_circuit(circuit, ansatz_params, prev_states, qubits=None, penalty=10.0, n_layers=2)[source]#

Apply a VQD ansatz circuit to circuit.

Variational Quantum Deflation (VQD) is a hybrid algorithm for finding excited states of a Hamiltonian one at a time. It minimises the cost function

\[C(\boldsymbol{\theta}) = \langle\psi(\boldsymbol{\theta})|H|\psi(\boldsymbol{\theta})\rangle + \sum_i \beta_i\,|\langle\psi(\boldsymbol{\theta})|\phi_i\rangle|^2\]

where \(|\phi_i\rangle\) are previously found lower-energy states and \(\beta_i\) are penalty coefficients.

This function only constructs the parameterised ansatz on the circuit. The overlap penalty terms are evaluated separately (see vqd_overlap_circuit()) and combined by a classical optimiser.

Parameters:
  • circuit (Circuit) – Quantum circuit to operate on (mutated in-place).

  • ansatz_params (List[float]) – Parameters for the HEA ansatz.

  • prev_states (List[ndarray]) – List of previously found state vectors (used by the classical optimiser, not directly in this circuit).

  • qubits (List[int] | None) – Qubit indices. None means all qubits of circuit.

  • penalty (float) – Penalty coefficient \(\beta\) (used by the caller).

  • n_layers (int) – Number of HEA layers.

Raises:

ValueError – If prev_states is empty (use VQE for the ground state).

Return type:

None

Example

>>> from uniqc.circuit_builder import Circuit
>>> import numpy as np
>>> c = Circuit(2)
>>> gs = np.array([1, 0, 0, 0], dtype=complex)
>>> vqd_circuit(c, [0.1]*4, prev_states=[gs], n_layers=2)
uniqc.algorithmics.circuits.vqd.vqd_overlap_circuit(prev_state, ansatz_params, n_layers=2, qubits=None)[source]#

Build a circuit to compute \(|\langle\psi(\boldsymbol{\theta})|\phi\rangle|^2\).

Uses the swap test: an ancilla qubit controls SWAPs between the ansatz register and a register prepared in prev_state. Measuring the ancilla in the computational basis gives an estimate of the overlap.

Circuit layout (2 data qubits):

ancilla: ──H──●──────●──●──────●── Measure
               |      |  |      |
data_A:  ──[ansatz]──SWAP──[ansatz]──SWAP──
               |      |  |      |
data_B:  ──[prev]──SWAP──[prev]──SWAP──
Parameters:
  • prev_state (ndarray) – State vector \(|\phi\rangle\) of dimension \(2^n\).

  • ansatz_params (List[float]) – Parameters for the HEA ansatz.

  • n_layers (int) – Number of HEA layers.

  • qubits (List[int] | None) – Data qubit indices for the ansatz register. None means [0, 1, …, n-1] where n is inferred from prev_state.

Returns:

A new Circuit containing the swap-test circuit with the ancilla measured.

Raises:

ValueErrorprev_state is not a power-of-2 length.

Return type:

Circuit

Example

>>> import numpy as np
>>> gs = np.array([1, 0, 0, 0], dtype=complex)
>>> circ = vqd_overlap_circuit(gs, [0.1]*4, n_layers=2)