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.

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

Build a VQD ansatz circuit fragment.

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

n_qubits may be None if qubits is given, in which case it is inferred as max(qubits) + 1.

uniqc.algorithms.core.circuits.vqd.vqd_example()[source]

Return a small VQD ansatz fragment for tests/docs.

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.

qubits names the ansatz register exactly. The ancilla and previous-state register are allocated from the lowest unused non-negative indices.

Parameters:
  • prev_state – State vector \(|\phi\rangle\) of dimension \(2^n\).

  • ansatz_params – Parameters for the HEA ansatz.

  • n_layers – Number of HEA layers.

  • qubits – 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.

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)