Skip to main content

Haiqu.vector_loading(data: Sequence[Number], num_qubits: int | None = None, num_layers: int = 2, truncation_cutoff: Real = 1e-06, fine_tuning_iterations: int = 20, name: str | None = None) → DataLoadingJobModel

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.
    • num_qubits — (int | None): The number of qubits in the generated circuit. If None (default), it is set automatically from the size of the data.
    • num_layers (int) — The number of layers in the generated circuit. 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.
    • 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.
  • 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, fidelity = job.result()  # vl_gate is a Qiskit-compatible gate
>>> 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
     └────────────────────────────────────────────────────────────┘