Open HGmin1159 opened 2 years ago
If you want to define a parameterized initialize instruction you can use the RawFeatureVector
of Qiskit ML:
>>> from qiskit_machine_learning.circuit.library import RawFeatureVector
>>> from qiskit.circuit import QuantumCircuit
>>> circuit = QuantumCircuit(3)
>>> circuit.compose(RawFeatureVector(2 ** circuit.num_qubits), inplace=True)
>>> circuit.draw()
┌───────────────────────────────────────────────────────────────────┐
q_0: ┤0 ├
│ │
q_1: ┤1 Parameterizedinitialize(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]) ├
│ │
q_2: ┤2 ├
└───────────────────────────────────────────────────────────────────┘
>>> bound = circuit.bind_parameters(list(range(8)))
>>> bound.decompose().draw()
┌─────────────────────────────────────────────────────────────────────────┐
q_0: ┤0 ├
│ │
q_1: ┤1 Initialize(0,0.084515,0.16903,0.25355,0.33806,0.42258,0.50709,0.59161) ├
│ │
q_2: ┤2 ├
└─────────────────────────────────────────────────────────────────────────┘
Oh, I didn't know that. Thank you sir. Maybe I need to check all of the relevant qiskit functions and organize them.
Thank you again.
If we want to have this feature in Terra we can just port it from Qiskit Machine Learning 🙂 I think we actually wanted to do this some time ago but never got around to doing it 😄
Would it be fair to rename this issue to QuantumCircuit.initialize() does not support parameters
?
Done it. Thank you Sir. I've never used github issue before ,so I didn't know there is a name in issue lol.
What is the expected enhancement?
I found that when I built custom data encoding methods in parameterized quantum circuit, we cannot use parameter instance(;qiskit.circuit.Parameter) at the qiskit.QuantumCircuit.initialize() function. It returned error according to follow code in qiskit.QuantumCircuit.initialize line 74~75 because the contemporary parameter instance cannot works with numpy.absolute.
So I changed the code as follow and tested simple circuits.
I could find that ratio of counts are almost similar with intended encoding probability which is ideal result. There is a table of result below. If we can use them, we can encode data into amplitudes like which can be used in many situation because it perfectly matches with the form of real Euclidean vector. Above refinement is not perfect because it cannot catch the vector norm problem when binding real parameter. But I think the advantages of implementing the amplitude encoding overweight the problem. So maybe we can use it until new version comes out