Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.haiqu.ai/llms.txt

Use this file to discover all available pages before exploring further.

Haiqu.isometry_encoding(data: Sequence[Real], density: int | None = 2, num_qubits: int | None = None, real: bool = True, periodicity: bool = False, num_layers: int = 2, truncation_cutoff: Real = 1e-06, fine_tuning_iterations: int = 20, name: str | None = None) → DataLoadingJobModel

Generate a quantum circuit that produces isometry encoding of the real data into a quantum state of a controllable entanglement. 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 complexity and quality of the generated circuit can be controlled by the num_layers, truncation_cutoff, and fine_tuning_iterations parameters.
  • Parameters:
    • data (Sequence *[*Real ]) — The real vector with data to encode.
    • density — (int | None): Feature density of the encoding. Larger values result in more features encoded per qubit but resulting quantum states are more entangled. Ignored if num_qubits is set, in which case the minimal density that is compatible with the given number of qubits is chosen. Defaults to 2.
    • num_qubits — (int | None): number of qubits for the isometry encoding. If None, then it is set automatically from data size. Otherwise, it uses given number of qubits and automatically sets the minimal possible density. Data vector is extended with zero padding if necessary. The general scaling of the data size, which can be encoded, is O(num_qubits * density ^2), up to small corrections. Defaults to None.
    • real (bool) — if True, then a real quantum state is prepared, otherwise imaginary part is also used, doubling the amount of features, which can be encoded in the same isometries. Defaults to True.
    • periodicity (bool) — if True, then additional tangent transform is performed over data, adding periodicity properties to the encoding. With density==1 it matches angular encoding. Defaults to False.
    • 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
>>> # loading a state with angular encoding
>>> feature_vector = [1, 2, 3, 4, 5]
>>> job = haiqu.isometry_encoding(data=feature_vector, density=1, periodicity=True, name="Angular encoding")
>>> ae_gate, fidelity = job.result()  # ae_gate is a Qiskit-compatible gate
>>> print(f"Angular encoding was loaded with fidelity {fidelity:.6f}")
Angular encoding was loaded with fidelity 1.000000
>>> print(f"Angular encoding required {job.num_qubits} qubits")
Angular encoding required 5 qubits
>>> circuit = qiskit.QuantumCircuit(job.num_qubits)
>>> circuit.append(ae_gate, range(job.num_qubits))
>>> circuit.draw()
     ┌────────────────────────────────────────────────────────────┐
q_0: ┤0
     │                                                            │
q_1: ┤1
     │                                                            │
q_2: ┤2 Haiqucircuit(circ-12345678-1234-5678-1234-567812345678,5) ├
     │                                                            │
q_3: ┤3
     │                                                            │
q_4: ┤4
     └────────────────────────────────────────────────────────────┘
>>> # loading a state into a more entangled Hilbert subspace
>>> feature_vector = [1, 2, 3, 4, 5]
>>> job = haiqu.isometry_encoding(data=feature_vector, density=2, name="Isometry encoding")
>>> ie_gate = job.result()  # ie_gate is a Qiskit-compatible gate
>>> fidelity = job.quality
>>> print(f"Isometry encoding was loaded with fidelity {fidelity:.6f}")
Isometry encoding was loaded with fidelity 1.000000
>>> print(f"Isometry encoding required {job.num_qubits} qubits")
Isometry encoding required 3 qubits