Haiqu.function_loading(num_qubits, func, interval_start, interval_end, synthesis_options=None, num_layers=None, truncation_cutoff=None, fine_tuning_iterations=None, max_time=900, name=None)
Generate a quantum circuit that prepares the values of a single-variable function in its amplitudes. Given a functionf(x), this method creates a Data Loading job that runs in the Haiqu cloud. The result of this
job is a circuit gate which prepares a state whose amplitudes are the function values, L2-normalized as a quantum state.
The resulting gate can be used to supply the function to a quantum algorithm for processing.
The function is provided as a SymPy expression or as a string, and must depend on the
single variable x only (e.g. "sin(x)", "exp(-x**2)", "x**2 + 1"). The variable x is real-valued
and ranges over the real interval [interval_start, interval_end]. The function values may be complex even though
x is real; the imaginary unit can be written Python-style as 1j or SymPy-style as I
(e.g. "exp(1j*x)" or "exp(I*x)").
The function is discretized on a grid of 2**num_qubits points: it is evaluated at the center (midpoint) of each
bin of the interval, and the resulting values are normalized as a quantum state. Singularities and non-finite values
(nan, +/-inf) are nullified (set to 0).
The complexity and quality of the generated circuit are controlled by synthesis_options.
NOTE
Amplitude indexing (Qiskit little-endian). The prepared state has2**num_qubitsamplitudes.data[i]is the amplitude for computational-basis indexi, where the rightmost bit ofiis qubit 0 (q_0). For example, with 2 qubits,data = [a, b, c, d]preparesa|00⟩ + b|01⟩ + c|10⟩ + d|11⟩. Apply the returned gate withcircuit.append(gate, range(num_qubits))so gate wirekacts onq_k. Inspect amplitudes after loading withstatevector_run().
NOTE
Discretization order. The interval[interval_start, interval_end]is divided into2**num_qubitsequal bins. Bini(counting from 0) spans increasing position along the interval, and its midpoint value becomes amplitude indexiusing the same Qiskit little-endian basis indexing asvector_loading()(rightmost bit ofiisq_0).
- Parameters:
- num_qubits (int) — The number of qubits in the generated circuit (from 1 to 1000 qubits).
- func (str | sympy.Expr) — The function to encode, given as a SymPy expression or a string in the single
variable
x. - interval_start (Real) — The beginning of the interval on which the function is sampled.
- interval_end (Real) — The end of the interval on which the function is sampled. The interval width
interval_end - interval_startmust be at least 1e-08. - synthesis_options (dict | DataLoadingSynthesisOptions) — How the circuit
preparing the data is synthesized. Pass one of
AnalyticalSynthesisOptions,BlockwiseSynthesisOptionsorVariationalSynthesisOptions, or an equivalent dict whose"method"key names one of them. Those three classes document every option each method accepts, what it means and what it defaults to. Defaults toNone, which this method unwraps intoAnalyticalSynthesisOptions(num_layers=2, layer_type="V", bond_dim_layer=2, entanglement_cutoff=1e-6, fine_tuning_iterations=20). - num_layers (int) — Deprecated. Pass
num_layersinsidesynthesis_options. - truncation_cutoff (Real) — Deprecated. Renamed to
entanglement_cutoffinsidesynthesis_options. - fine_tuning_iterations (int) — Deprecated. Pass
fine_tuning_iterationsinsidesynthesis_optionsinstead. - max_time (int | float) — Soft time limit for the job (in seconds). The data loading job will first always produce the initial result and then limit the fine-tuning stage by the remaining time left. If time limit exceeds during the fine-tuning - the best current result will be returned. Defaults to 900 (15 min). Max allowed job time is 15 min. The job can take more wall clock time than user specified max_time due to latency, initialization overheads or if the initial result already takes more time.
- name (str | None) — The name for the job and the produced circuit. If
None(default), a name will be automatically generated.
- Returns:
The Data Loading job that will generate the circuit for the function.
: Call
job.result()to retrieve a Qiskit-compatible gate (HaiquCircuitGate) that prepares the function values.job.qualityis the achieved state fidelity vs. the ideal target function;job.infoexposes loader metadata (fidelity). Runhelp(job.result)for the full description of result andinfocontents. In a notebook, a link to the job on the Dashboard is also displayed whenhaiqu.verbosityis"high". - Return type: DataLoadingJobModel
Examples
Encoding a Gaussian given as a SymPy expression:1j and I are equivalent):