Skip to main content

Haiqu.vector_loading(data, num_qubits=None, synthesis_options=None, num_layers=None, truncation_cutoff=None, fine_tuning_iterations=None, max_time=900, name=None, job_description=None)

Generate a quantum circuit that prepares an arbitrary real or complex vector. Given a vector of data, 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 vector to a quantum algorithm for processing. The cost and time of this job can be estimated with vector_loading_estimates(). The complexity and quality of the generated circuit are controlled by synthesis_options. If len(data) < 2**num_qubits, the vector will be padded with zeros.

NOTE

Amplitude indexing (Qiskit little-endian). The prepared state has 2**num_qubits amplitudes. data[i] is the amplitude for computational-basis index i, where the rightmost bit of i is qubit 0 (q_0). For example, with 2 qubits, data = [a, b, c, d] prepares a|00⟩ + b|01⟩ + c|10⟩ + d|11⟩. Apply the returned gate with circuit.append(gate, range(num_qubits)) so gate wire k acts on q_k. Inspect amplitudes after loading with statevector_run().

NOTE

Multiple calls with identical inputs will generate multiple circuits. To save time, persist the job ID together with your results rather than re-running the loading job.
  • Parameters:
    • data (Sequence *[*Number ]) — The vector with data to encode (length of data is from 1 to 2**20 values). data[i] is the amplitude for basis index i in Qiskit little-endian order (rightmost bit of i is qubit 0).
    • num_qubits (int | None) — (int | None): The number of qubits in the generated circuit (from 1 to 20 qubits). If None (default), it is set automatically from the size of the data.
    • synthesis_options (dict | DataLoadingSynthesisOptions) — How the circuit preparing the data is synthesized. Pass one of AnalyticalSynthesisOptions, BlockwiseSynthesisOptions or VariationalSynthesisOptions, 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 to None, which this method unwraps into AnalyticalSynthesisOptions(num_layers=2, layer_type="V", bond_dim_layer=2, entanglement_cutoff=1e-6, fine_tuning_iterations=20).
    • num_layers (int) — Deprecated. Pass num_layers inside synthesis_options.
    • truncation_cutoff (Real) — Deprecated. Renamed to entanglement_cutoff inside synthesis_options.
    • fine_tuning_iterations (int) — Deprecated. Pass fine_tuning_iterations inside synthesis_options instead.
    • 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.
    • job_description (str | None)
  • Returns: The Data Loading job that will generate the circuit for the data vector. : Call job.result() to retrieve a Qiskit-compatible gate (HaiquCircuitGate) that prepares the input data vector. job.quality is the achieved state fidelity vs. the ideal target vector; job.info exposes loader metadata (fidelity). Run help(job.result) for the full description of result and info contents. In a notebook, a link to the job on the Dashboard is also displayed when haiqu.verbosity is "high".
  • Return type: DataLoadingJobModel

Examples

Choose the synthesis method and its options explicitly:

Haiqu.vector_loading_estimates(data, num_qubits=None, synthesis_options=None, num_layers=None, truncation_cutoff=None, fine_tuning_iterations=None, max_time=900, name=None, job_description=None)

Estimate the cost and time of a Data Loading job created by vector_loading(). The parameters are the same as for vector_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 vector_loading().
  • Parameters:
    • data (Sequence *[*Number ]) — The vector with data to encode (length of data is from 1 to 2**20 values). data[i] is the amplitude for basis index i in Qiskit little-endian order (rightmost bit of i is qubit 0).
    • num_qubits (int | None) — (int | None): The number of qubits in the generated circuit (from 1 to 20 qubits). If None (default), it is set automatically from the size of the data.
    • synthesis_options (dict | DataLoadingSynthesisOptions) — How the circuit preparing the data is synthesized. Pass one of AnalyticalSynthesisOptions, BlockwiseSynthesisOptions or VariationalSynthesisOptions, 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 to None, which this method unwraps into AnalyticalSynthesisOptions(num_layers=2, layer_type="V", bond_dim_layer=2, entanglement_cutoff=1e-6, fine_tuning_iterations=20).
    • num_layers (int) — Deprecated. Pass num_layers inside synthesis_options.
    • truncation_cutoff (Real) — Deprecated. Renamed to entanglement_cutoff inside synthesis_options.
    • fine_tuning_iterations (int) — Deprecated. Pass fine_tuning_iterations inside synthesis_options instead.
    • 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.
    • job_description (str | None)
  • Returns: The estimated time (in seconds) and cost (in Haiqu Credits).
  • Return type: DataLoadingEstimatesModel

Examples