Skip to main content

Haiqu.vector_loading(data, num_qubits=None, num_layers=2, truncation_cutoff=1e-06, fine_tuning_iterations=20, max_time=900, name=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 can be controlled by the num_layers, truncation_cutoff, and fine_tuning_iterations parameters. If len(data) < 2**num_qubits, the vector will be padded with zeros.
  • Parameters:
    • data (Sequence *[*Number ]) — The vector with data to encode (length of data is from 1 to 2**20 values).
    • 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.
    • 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 vector at the cost of a deeper circuit. Defaults to 2.
    • 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.
    • fine_tuning_iterations (int) — The maximum number of fine-tuning iterations to perform after each layer is added. Increasing this limit may improve the quality of the circuit by using more classical resources. Defaults to 20, maximal is 200.
    • 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 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.
  • Return type: DataLoadingJobModel

Examples

>>> bell_state = [1, 0, 0, 1]  # normalization is not required
>>> job = haiqu.vector_loading(data=bell_state, name="Bell state Vector Loading")
>>> vl_gate = job.result()  # vl_gate is a Qiskit-compatible gate
>>> fidelity = job.quality
>>> print(f"Bell state was loaded with fidelity {fidelity:.6f}")
Bell state was loaded with fidelity 1.000000
>>> print(f"Vector loading required {job.num_qubits} qubits")
Vector loading required 2 qubits
>>> circuit = qiskit.QuantumCircuit(job.num_qubits)
>>> circuit.append(vl_gate, range(job.num_qubits))
>>> circuit.draw()
     ┌────────────────────────────────────────────────────────────┐
q_0: ┤0
     │  Haiqucircuit(circ-12345678-1234-5678-1234-567812345678,2) │
q_1: ┤1
     └────────────────────────────────────────────────────────────┘

Haiqu.vector_loading_estimates(data, num_qubits=None, num_layers=2, truncation_cutoff=1e-06, fine_tuning_iterations=20, max_time=900, name=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).
    • 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.
    • 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 vector at the cost of a deeper circuit. Defaults to 2.
    • 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.
    • fine_tuning_iterations (int) — The maximum number of fine-tuning iterations to perform after each layer is added. Increasing this limit may improve the quality of the circuit by using more classical resources. Defaults to 20, maximal is 200.
    • 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 estimated time (in seconds) and cost (in Haiqu Credits).
  • Return type: DataLoadingEstimatesModel

Examples

>>> est = haiqu.vector_loading_estimates(
...     num_qubits=10,
...     num_layers=5,
>>> )
>>> est
DataLoadingEstimatesModel(estimated_time=221.07399999999998, estimated_cost=0.06308276)
>>> est.draw()  # in Jupyter notebook