Skip to main content

Haiqu.distribution_loading(num_qubits, distribution_name, interval_start, interval_end, loc=0, scale=1, num_layers=1, truncation_cutoff=1e-06, name=None, **shape)

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 (from 1 to 1000 qubits).
    • 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 (from 1 to 15 layers). 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. : Call job.result() to retrieve a Qiskit-compatible gate (HaiquCircuitGate) that prepares the requested probability distribution on num_qubits qubits. job.quality is the achieved state fidelity vs. the ideal target distribution; job.info exposes loader metadata (fidelity). Run help(job.result) for the full description of result and info contents.
  • 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 = job.result()  # dl_gate is a Qiskit-compatible gate
>>> fidelity = job.quality
>>> 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
     └────────────────────────────────────────────────────────────┘

Haiqu.distribution_loading_estimates(num_qubits, distribution_name, interval_start, interval_end, loc=0, scale=1, num_layers=1, truncation_cutoff=1e-06, name=None, **shape)

Estimate the cost and time of a Data Loading job created by distribution_loading(). The parameters are the same as for distribution_loading(). Once you discover values that result in acceptable cost and time estimates, you can remove _estimates from the end of the method name and call distribution_loading().
  • Parameters:
    • num_qubits (int) — The number of qubits in the generated circuit (from 1 to 1000 qubits).
    • 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 (from 1 to 15 layers). 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 estimated time (in seconds) and cost (in Haiqu Credits).
  • Return type: DataLoadingEstimatesModel

Examples

>>> est = haiqu.distribution_loading_estimates(
...     num_qubits=10,
...     distribution_name="norm",
...     interval_start=-3,
...     interval_end=3
>>> )
>>> est
DataLoadingEstimatesModel(estimated_time=0.22770169152050562, estimated_cost=0.010079648405964921)
>>> est.draw()  # in Jupyter notebook