• Members 12 posts
    Sept. 4, 2021, 9:07 a.m.

    I have a classical vector, which I want to encode it into amplitudes of qubits. The purpose is to implement it in Quantum Neural Networks. For this, I need help for the following:

    How can I encode a vector of numbers into qubits? e.g.

    vector = [1/2, 1/2, 1/2, 1/2]
    

    If it is a vector of parameters, how to does the encoding work?

  • Members 17 posts
    Sept. 4, 2021, 9:56 a.m.

    To encode a vector of numbers, you can simply to initialize in qiskit.

    from qiskit import QuantumCircuit
    n = 2
    circuit = QuantumCircuit(n)
    vector = [1/2, 1/2, 1/2, 1/2]
    circuit.initialize(vector)
    

    The number of elements in the vector should equal to 2^n, where n is the number of qubits. If the number of entries is less than 2^n, one can zero the remaining elements in the vector. The vector has to be normalized.

    To encode parameters into a quantum circuit, EfficientSU2 provides a very convenient way

    from qiskit.circuit.library import EfficientSU2
    circuit = EfficientSU2(n, reps=1)
    
  • edit

    Thread title has been changed from Encoding a classical vector into amplitudes of qubits for state preparation in qiskit.