-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong parameters assignment in the tutorial 11_quantum_convolutional_neural_networks #678
Comments
Please look at the linked PR above #728. That addressed a different issue to start with but I needed to address the notebook you refer to in this issue where I saw the problem with "c1" and changed it. I believe the PR addresses this issue so I set it to close it. |
@woodsp-ibm Thanks for your reply. I have not patched and run the codes, however I have looked at the implementation of |
A |
OK... I checked Qiskit's source codes and recognized that I understand that, as the alphabetical order, >>> "inputs" < "weights"
True so, I also checked by writing snippets below with being aware >>> from qiskit import QuantumCircuit
>>> from qiskit.circuit import ParameterVector
>>> x = ParameterVector("x", 1)
>>> w = ParameterVector("w", 1)
>>> qc = QuantumCircuit(1)
>>> qc.ry(x[0], 0)
<qiskit.circuit.instructionset.InstructionSet object at 0x7fa3fc8e5bd0>
>>> qc.ry(w[0], 0)
<qiskit.circuit.instructionset.InstructionSet object at 0x7fa3fc8e5c90>
>>> qc.draw("text")
┌──────────┐┌──────────┐
q: ┤ Ry(x[0]) ├┤ Ry(w[0]) ├
└──────────┘└──────────┘
>>> qc.parameters
ParameterView([ParameterVectorElement(w[0]), ParameterVectorElement(x[0])])
>>> new_x = ParameterVector("in", 1)
>>> qc = qc.assign_parameters({x[0]: new_x[0]})
>>> qc.parameters
ParameterView([ParameterVectorElement(in[0]), ParameterVectorElement(w[0])])
>>> qc.draw("text")
┌───────────┐┌──────────┐
q: ┤ Ry(in[0]) ├┤ Ry(w[0]) ├
└───────────┘└──────────┘ |
Right what's important in the end, is that the data is bound by the primitive (Estimator or Sampler) where the the list of values passed is bound in the order that qc.parameters returns. As the data in the QNNs is ordered inputs then outputs in the data values array passed the parameters need to be the same order. With the standard library feature map circuit using "x" and circuit library anstazes using greek theta this was normally the case but that cannot be guaranteed for any circuit. Hence this rewriting ensures this is the case, that what the user says are input and weight params in the sequences passed, the data truly gets bound in that order no matter the original naming. |
Environment
What is happening?
I suspect that wrong parameters assignment occurs in the
NeuralNetworkClassifier
of 11_quantum_convolutional_neural_networks.html.How can we reproduce the issue?
It is difficult to explain in words, so I created a notebook: 11_quantum_convolutional_neural_networks_issue.ipynb
So you can reproduce the issue by executing the attached notebook.
In short,
train_images
data are assigned to the conv layer whose name is"c2"
and the parameters from11_qcnn_initial_point.json
are assigned toParameterVectorElement(c2[8])
,ParameterVectorElement(c2[9])
, ...The contents up to cell No.14 are the same as in the tutorial. However, only cell No.13 has
maxiter=0
to finish immediately. My explanation will start from the cell No.15.What should happen?
I think
train_images
data should be assigned tox[0]
,x[1]
, ... and the parameters from11_qcnn_initial_point.json
should be assigned toc1[0]
,c1[1]
, ...Note that
c
ofc1
in the tutorial is actually not a latin characterc
(LATIN SMALL LETTER C; U+0063) but a cyrillic characterс
(CYRILLIC SMALL LETTER ES; U+0441). After c2,c
of c2, c3 are LATIN SMALL LETTER C.Any suggestions?
No response
The text was updated successfully, but these errors were encountered: