hqs_quantum_solver.qubits#

This module provides operators for quantum circuits.

Functions

bits_to_int(bits)

Converts a bit list in little endian format to an integer.

extended_gate(gate, targets[, controls])

Extend a gate to a larger circuit and add control lanes.

hadamard_gate([target])

The Hadamard gate applied to a given target.

int_to_bits(number, /, length)

Convert an integer to a bit list in little endian format.

iqft()

The inverse quantum Fourier transform.

mod_mul(a, q, /)

Gate for the multiplication in modular arithmetic where a is coprime to q.

not_gate([target])

The not gate applied to a given target.

qft()

The quantum Fourier transform.

y_gate([target])

The \(Y\) gate applied to a given target.

z_gate([target])

The \(Z\) gate applied to a given target.

bits_to_int(bits: Sequence[int]) int#

Converts a bit list in little endian format to an integer.

Parameters:

bits (Sequence[int]) – A sequence of zeros and ones.

Returns:

The encoded integer.

Return type:

int

extended_gate(gate: Operator, targets: list[int], controls: list[int] | None = None) Expression[MatrixEntryGenerator]#

Extend a gate to a larger circuit and add control lanes.

The result of this operation is a gate that applies the given gate to the target registers while applying the identity to all other registers. If any of the control registers is zero, the entire operation is replaced by the identity.

Warning

This function is part of an experimental API and might be subject to change.

Parameters:
  • gate (Operator) – The original gate on the small circuit.

  • targets (list[int]) – The list of target registers.

  • controls (list[int]) – The list of control registers.

hadamard_gate(target: int = 0) Expression[MatrixEntryGenerator]#

The Hadamard gate applied to a given target.

The gate is defined by

\[\begin{split}\begin{aligned} \textrm{H}_t ( \cdots | 0 \rangle \cdots ) &= ( \cdots | + \rangle \cdots ) \\ \textrm{H}_t ( \cdots | 1 \rangle \cdots ) &= ( \cdots | - \rangle \cdots ) \,, \end{aligned}\end{split}\]

where \(\ket{+} = \frac{1}{\sqrt{2}} ( \ket{0} + \ket{1} )\) and \(\ket{-} = \frac{1}{\sqrt{2}} ( \ket{0} - \ket{1} )\).

Warning

This function is part of an experimental API and might be subject to change.

Parameters:

target (int) – The target register.

int_to_bits(number: int, /, length: int) list[int]#

Convert an integer to a bit list in little endian format.

Parameters:
  • number (int) – The number to conver.

  • length (int) – The number of bits to use.

Returns:

A list of zeros and ones representing the input.

Return type:

list[int]

iqft() Expression[MatrixEntryGenerator]#

The inverse quantum Fourier transform.

We write \(| b_0 b_1 \cdots \rangle\) as \(\ket{i}\), where \(b_0 b_1 \cdots\) is the little endian binary representation of \(i\), i.e., \(i = b_0 \cdot 2^0 + b_1 \cdot 2^1 + b_2 \cdot 2^2 + \cdots\). Then, the inverse quantum Fourier transform is given by

\[\bra{j} \mathrm{QFT} \ket{\psi} = \frac{1}{\sqrt{N}} \sum_{k = 0}^{N-1} \braket{k | \psi} e^{\frac{-2 \pi \mathrm{i}}{N} jk} \,.\]

Warning

The sign in the exponent is different than from what you would expect by comparing it to a typical definition of the discrete Fourier transform.

Warning

This function is part of an experimental API and might be subject to change.

mod_mul(a: int, q: int, /) Expression[MatrixEntryGenerator]#

Gate for the multiplication in modular arithmetic where a is coprime to q.

We write \(| b_0 b_1 \cdots \rangle\) as \(\ket{i}\), where \(b_0 b_1 \cdots\) is the little endian binary representation of \(i\), i.e., \(i = b_0 \cdot 2^0 + b_1 \cdot 2^1 + b_2 \cdot 2^2 + \cdots\).

\[\begin{split}\mathop{\mathrm{mod\,mul}} \ket{b} = \begin{cases} \ket{ (a \cdot b) \mathrel{\mathrm{mod}} q } & \text{if } b < q \\ \ket{ b } & \text{otherwise.} \end{cases}\end{split}\]

Note

All states representing a number larger or equal of \(q\) are mapped to themselves, otherwise the operation would not be unitary.

Warning

This function is part of an experimental API and might be subject to change.

Parameters:
  • a (int) – The factor.

  • q (int) – The modulus.

not_gate(target: int = 0) Expression[MatrixEntryGenerator]#

The not gate applied to a given target.

The gate is defined by

\[\begin{split}\begin{aligned} \textrm{NOT}_t ( \cdots | 0 \rangle \cdots ) &= ( \cdots | 1 \rangle \cdots ) \\ \textrm{NOT}_t ( \cdots | 1 \rangle \cdots ) &= ( \cdots | 0 \rangle \cdots ) \,. \end{aligned}\end{split}\]

Warning

This function is part of an experimental API and might be subject to change.

Parameters:

target (int) – The target register.

qft() Expression[MatrixEntryGenerator]#

The quantum Fourier transform.

We write \(| b_0 b_1 \cdots \rangle\) as \(\ket{i}\), where \(b_0 b_1 \cdots\) is the little endian binary representation of \(i\), i.e., \(i = b_0 \cdot 2^0 + b_1 \cdot 2^1 + b_2 \cdot 2^2 + \cdots\). Then, the quantum Fourier transform is given by

\[\bra{k} \mathrm{QFT} \ket{\psi} = \frac{1}{\sqrt{N}} \sum_{j = 0}^{N-1} \braket{j | \psi} e^{\frac{2 \pi \mathrm{i}}{N} jk} \,.\]

Warning

The sign in the exponent is different than from what you would expect by comparing it to a typical definition of the discrete Fourier transform.

Warning

This function is part of an experimental API and might be subject to change.

y_gate(target: int = 0) Expression[MatrixEntryGenerator]#

The \(Y\) gate applied to a given target.

The gate is defined by

\[\begin{split}\begin{aligned} \textrm{Y}_t ( \cdots | 0 \rangle \cdots ) &= \mathrm{i} ( \cdots | 1 \rangle \cdots ) \\ \textrm{Y}_t ( \cdots | 1 \rangle \cdots ) &= -\mathrm{i} ( \cdots | 0 \rangle \cdots ) \,. \end{aligned}\end{split}\]

Warning

This function is part of an experimental API and might be subject to change.

Parameters:

target (int) – The target register.

z_gate(target: int = 0) Expression[MatrixEntryGenerator]#

The \(Z\) gate applied to a given target.

The gate is defined by

\[\begin{split}\begin{aligned} \textrm{Z}_t ( \cdots | 0 \rangle \cdots ) &= ( \cdots | 0 \rangle \cdots ) \\ \textrm{Z}_t ( \cdots | 1 \rangle \cdots ) &= -( \cdots | 1 \rangle \cdots ) \,. \end{aligned}\end{split}\]

Warning

This function is part of an experimental API and might be subject to change.

Parameters:

target (int) – The target register.