0
$\begingroup$

I want to encode classical data into quantum data. For that, I know qiskit has a feature map : the ZZFeatureMap. So I build a quantum circuit with this ZZFeatureMap following qiskit's documentation:

qc = QuantumCircuit(2, 2)
feature_map = ZZFeatureMap(2, reps=1)
ansatz = RealAmplitudes(2)
qc.compose(feature_map, inplace=True)
qc.compose(ansatz, inplace=True)
qc.measure([0,1], [0,1])

enter image description here

But now, let's say I have the classical data : data=[10, 42]

How can I input my classical data into the ZZFeatureMap circuit ? My goal is then to run simulations to see what the encoding does.

$\endgroup$
1
  • $\begingroup$ I think I just found out : I added bind_parameters(data) in my feature_map. If someone can confirm that's how you do ? $\endgroup$
    – Duen
    Commented Mar 13, 2023 at 17:39

1 Answer 1

1
$\begingroup$

As you already noticed, we use QuantumCircuit.bind_parameters() method to encode our classical dataset as rotations on ZZFeatureMap's parameterized gates.

data = [0.1, 0.2]
feature_map = ZZFeatureMap(2, reps=1)
feature_map = feature_map.bind_parameters(data) # <== here

qc = QuantumCircuit(2, 2)
qc.compose(feature_map, inplace=True)

ansatz = RealAmplitudes(2)
qc.compose(ansatz, inplace=True)

qc.measure([0,1], [0,1])

Note: since the data is encoded as angle rotations, you need to normalize it to be in the interval $(0, 2\pi]$.

ZZ feature map is introcuded in the paper "Supervised learning with quantum enhanced feature spaces" by Havlíček et. la. (2019)

For more details, see: here and here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.