Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.haiqu.ai/llms.txt

Use this file to discover all available pages before exploring further.

A key challenge in quantum computing applications — such as quantum machine learning, finance, and optimization — is efficiently encoding classical data into quantum states. In this tutorial, we’ll load a classical probability distribution (like the normal distribution) into a quantum state, which is a core primitive for various financial and simulation applications.
  • Goal: Encode a probability distribution into a quantum state such that measurement outcomes follow the target distribution.
  • Use Case: Financial modeling, probabilistic simulations, quantum generative models.
  • How it works: The square root of the distribution (e.g., Gaussian) is encoded in quantum amplitudes via state preparation circuits.
Haiqu SDK offers a simple function to load over 100 distributions supported by scipy.stats library. For example, loading a Normal distribution into the quantum state can be done by running the following function that initializes a data loading job:
job = haiqu.distribution_loading(
  name=f"DL norm {num_qubits}q",        # Name
  num_qubits=num_qubits,                # Number of qubits
  distribution_name="norm",             # Distribution to load
  interval_start=-3, interval_end=3,    # Interval over which to load
  num_layers=2                          # Precision parameter 
  )
The corresponding state preparation gate is returned by calling job.result()the job result:
data_loading_gate = job.result()  # a HaiquCircuitGate, encapsulating state preparation circuit
fidelity = job.quality            # fidelity of the state preparation circuit
Above fidelity quantifies the overlap between a wavefunction generated by the synthesized circuit and the exact discretized input distribution, computed as quantum state fidelity. The quality of the obtained data loading circuit can be visually verified using e.g. statevector simulation. For the Normal distribution example using num_qubits=8 we obtain the following result:
qc = QuantumCircuit(num_qubits)
# add the data loading gate to the circuit
qc.compose(data_loading_gate, inplace=True)

# run exact simulation
sv = haiqu.statevector_run(qc).result()[0]

# plot probabilities
plt.plot(np.square(np.abs(sv)))
Image
The required parameters of the distribution_loading method are:
  • distribution_name: name of the statistical distribution from scipy.stats.
  • interval_start and interval_end: the boundaries of the interval over which the distribution will be discretized before loading into the quantum state.
  • num_qubits : the number of qubits used, which sets the discretization resolution.
Additionally, the user can control advanced parameters, such as: Distribution Hyperparameters (Optional, follows SciPy’s API)
  • loc (default: 00) → The location/mean of the distribution.
  • scale (default: 11) → Scale or spread, often linked to variance.
  • shape parameters → Distribution-specific extra parameters. Check SciPy docs for details.
State Preparation Hyperparameters (Optional)
  • num_layers (default: 11) → Number layer in the data loading circuit. More layers = better approximation of data or distribution, but more gates.
  • truncation_cutoff (default: 1e-6) → A threshold for cutting off low-entanglement gates. Set to None or 0 for no truncation (full entanglement retained).

Distribution Loading Specifications

ParameterDetails
Number of qubitsUp to 1000 qubits
Number of distributions107 different classes of distributions are supported. Check SciPy docs for details.
Runtime1–15 seconds
Runtime scalingLinear scaling with number of qubits
Circuit size (gates count)O(n), n = number of qubits
Circuit depthO(n/2), n = number of qubits
Circuit connectivityLinear
Other circuit properties- No mid-circuit measurements
- Only CNOT and single-qubit rotation gates
- No ancillary qubits
- No post-selection required in state preparation
Returned metricsQuantum state fidelity is returned for the ideal state prepared by the circuit