Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself
Encoding classical data on quantum states is an important subroutine in variational quantum circuits, such as Quantum Singular Vector Machine (QSVM) and Quantum Neural Networks (QNN).

Encode in angle

This function encodes nn data points on nn qubits, mapping the data point xix_i to a RY rotation on the ii-th qubit with a πxi\pi x_i angle. Function: encode_in_angle Arguments:
  • data: CArray[Creal]
  • qba: Output[QArray[QBit]]
The qba quantum argument is the quantum state on which we encode the classical array data.

Example

from classiq import *


@qfunc
def main(data: CArray[CReal, 4], x: Output[QArray[QBit]]):
    encode_in_angle(data, x)


qmod = create_model(main)

from classiq import synthesize

qprog = synthesize(qmod)
png

Encode on Bloch

This function encodes nn data points on n/2\lceil n/2 \rceil, mapping pairs of data points (x2i,x2i+1)(x_{2i}, x_{2i+1}) to the bloch sphere via RX rotation with an angle πx2i\pi x_{2i} followed by a RZ rotation with an angle πx2i+1\pi x_{2i+1}. If the number of data points is odd then a single RX rotation is applied to the last qubit, with an angle of 2πxn2\pi x_n. Function: encode_on_bloch Arguments:
  • data: CArray[Creal]
  • qba: Output[QArray[QBit]]
The qba quantum argument is the quantum state on which we encode the classical array data.

Example

from classiq import *


@qfunc
def main(data: CArray[CReal, 7], x: Output[QArray[QBit]]):
    encode_on_bloch(data, x)


qmod = create_model(main)

from classiq import synthesize

qprog = synthesize(qmod)
png