circuit
eigenkit.orthogonal.circuit
Turn the angles of an orthogonal network into a quantum circuit.
The angles can come from anywhere, for example from a network trained classically
with the PyTorch modules. to_block fixes them as Constants in an RBSNetwork,
and to_circuit puts a UnaryLoader in front and the unary readout behind, so the
circuit runs on any provider, on a simulator or on hardware.
A circuit simulates a statevector of \(2^n\) amplitudes, so this form is limited to
about 20 wires. The matrix form, orthogonal_matrix, is the same map restricted to
the unary basis and scales to thousands of wires.
Example
import numpy as np
from eigenkit.orthogonal import (
orthogonal_matrix,
pyramid,
to_circuit,
unary_loader_angles,
unary_probabilities,
)
t = pyramid(4)
theta = np.random.default_rng(0).normal(size=t.n_angles)
circuit = to_circuit(t, theta)
x = np.array([1.0, 2.0, -0.5, 0.3])
p = unary_probabilities(circuit(np.zeros(0), unary_loader_angles(x)))
# p == (orthogonal_matrix(t, theta) @ x) ** 2 / (x @ x)
to_block(topology, theta)
An RBSNetwork block with fixed angles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topology
|
Topology
|
The gate layout. |
required |
theta
|
array - like
|
The angles, of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
RBSNetwork |
RBSNetwork
|
A block that takes no weights. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
to_circuit(topology, theta, loader='diagonal', provider='numpy')
A runnable circuit: a unary loader, the network with fixed angles, and the unary readout.
The circuit takes no weights. With a loader, its inputs are the \(n - 1\)
loader angles of unary_loader_angles(x, loader), and its outputs are
\(\langle Z_i \rangle\), from which unary_probabilities gives
\((Wx)_i^2 / \lVert x \rVert^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topology
|
Topology
|
The gate layout. |
required |
theta
|
array - like
|
The angles, of shape |
required |
loader
|
LoaderLayout | None
|
The layout of the |
'diagonal'
|
provider
|
ProviderSpec
|
The backend, as for |
'numpy'
|
Returns:
| Name | Type | Description |
|---|---|---|
Circuit |
Circuit
|
The compiled NumPy-interface circuit. |