Skip to main content

Haiqu.distribution_loading(num_qubits: int, distribution_name: str, interval_start: Real, interval_end: Real, loc: Real = 0, scale: Real = 1, num_layers: int = 1, truncation_cutoff: Real = 1e-06, name: str | None = None, **shape) → DataLoadingJobModel

Generate a quantum circuit that prepares a probability distribution. Given the description of a probability distribution function (PDF), this method creates a Data Loading job that runs in the Haiqu cloud. The result of this job is a circuit which can be used to supply the PDF to a quantum algorithm for processing. The cost and time of this job can be estimated with distribution_loading_estimates(). The complexity of the generated circuit can be controlled by the num_layers and truncation_cutoff parameters.
  • Parameters:
    • num_qubits (int) — The number of qubits in the generated circuit.
    • distribution_name (str) — The name of the distribution. Can be any of the continuous distributions in scipy.stats.
    • interval_start (Real) — The beginning of the interval.
    • interval_end (Real) — The end of the interval.
    • loc (Real) — The location to which to shift the distribution. Defaults to 0.
    • scale (Real) — The scaling factor by which to stretch the distribution. Defaults to 1.
    • num_layers (int) — The number of layers in the generated circuit. More layers can improve the quality of the output distribution at the cost of a deeper circuit. Defaults to 1.
    • truncation_cutoff (Real) — The entanglement cutoff for later layers. Increasing this threshold may result in a smaller (but more approximate) circuit. Defaults to 1e-6.
    • name (str | None) — The name for the job and the produced circuit. If None (default), a name will be automatically generated.
    • **shape — Additional distribution parameters, required by some distributions. Refer to the distribution documentation in scipy.stats for more details.
  • Returns: The Data Loading job that will generate the circuit for the probability distribution.
  • Return type: DataLoadingJobModel

Examples

>>> num_qubits = 4
>>> job = haiqu.distribution_loading(
...     num_qubits=num_qubits,
...     distribution_name="norm",
...     interval_start=-3,
...     interval_end=3,
...     name=f"Normal distribution ({num_qubits} qubits)",
>>> )
>>> dl_gate, fidelity = job.result()  # dl_gate is a Qiskit-compatible gate
>>> print(f"Normal distribution was loaded with fidelity {fidelity:.6f}")
Normal distribution was loaded with fidelity 0.999484
>>> circuit = qiskit.QuantumCircuit(num_qubits)
>>> circuit.append(dl_gate, range(num_qubits))
>>> circuit.draw()
     ┌────────────────────────────────────────────────────────────┐
q_0: ┤0
     │                                                            │
q_1: ┤1
     │  Haiqucircuit(circ-12345678-1234-5678-1234-567812345678,4) │
q_2: ┤2
     │                                                            │
q_3: ┤3
     └────────────────────────────────────────────────────────────┘