uniqc.algorithms.core.circuits.vqd module

Variational Quantum Deflation (VQD) circuit components.

uniqc.algorithms.core.circuits.vqd.vqd_ansatz(n_qubits, ansatz_params, prev_states, qubits=None, penalty=10.0, n_layers=2)[source]

Build a VQD ansatz circuit fragment (variational style).

Returns a fresh Circuit. prev_states is accepted to keep the VQD signature, but is only used by the classical optimiser.

Parameters:
Return type:

Circuit

uniqc.algorithms.core.circuits.vqd.vqd_circuit(*args, ansatz_params=None, prev_states=None, qubits=None, penalty=10.0, n_layers=2)[source]

Build (or apply) a VQD ansatz.

Two calling conventions:

# Variational fragment style (recommended; see also vqd_ansatz):
c = vqd_circuit(2, ansatz_params=[0.1]*4, prev_states=[gs], n_layers=2)

# Legacy in-place (deprecated):
c = Circuit(2)
vqd_circuit(c, [0.1]*4, prev_states=[gs], n_layers=2)
Parameters:
uniqc.algorithms.core.circuits.vqd.vqd_example()[source]

Return a small VQD ansatz fragment for tests/docs.

Return type:

Circuit

uniqc.algorithms.core.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)