-
Notifications
You must be signed in to change notification settings - Fork 358
Deprecate BlueprintCircuit based circuit usage #945
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
Conversation
Pull Request Test Coverage Report for Build 15491457210Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for this update Steve! I made some suggestions in the code. The plan seems to remove the class versions of the circuit library instances in 0.9.
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
I would not say remove, rather deprecate their usage, In examples, tests, notebooks the intent was to use the functions and only the class based ones minimally in unit tests to make sure things still work there. So code still works with both but one should be moving away from the class based ones over to the functions - whether its the Qiskit library ones or the functions I created for the class based library circuits in ML here. At some point down the road then yes they would be removed, but that's some unknown future version in my mind, not 0.9 |
I see you merged this, My intent, as per the todo in the PR at the start was to add a release note and update the tutorials to use functions where needed after the fundamental code changes I did had been seen, and agreed with, just in case. Maybe its my bad that I did not do this as a Draft. Still I can always do another PR of course, we do need a release note to talk about the deprecations here and it would be better if the tutorials were not using deprecated code. Maybe I'll do the release note in PR on its own so as that is at least that can be here too and tutorials can be looked at after. |
Summary
Closes #931
Move away from BlueprintCircuit based circuit usage
Todo:
I figured I'd check in the code changes ahead of doing the above just in case any alterations to what was done were wanted.
Details and comments
This updates machine learning to move away from BlueprintCircuit based classes and use instead the circuit library functions which create similar circuits but which cannot be updated the same way once created e.g num_qubits is fixed at creation time.
In ML here were
RawFeatureVector
andQNNCircuit
both of which are subclasses of BlueprintCircuit, These I deprecated but they can still be used and algorithms still accept the. Their "replacements" areraw_feature_vector
andqnn_circuit
methods which cannot be updated for num_bits etc similarly now to the qiskit circuit library functions.raw_feature_vector just returns a circuit - RawFeatureVector had a num_qubits getter, which by virtue of being a QusntumCircuit it still has, but the getter to get feature_dimension no longer has any way to specifically get this but its easy to compute as its 2 ** num_qhbuts.
qnn_circuit, this returns a circuit and the parameters for the underlying feature map and ansatz so they can be passed into a QNN, eg SamplerQNN directly. It performs the compose but also creates circuits based on number of qubits etc as before so since it was a bit more that a simple composition function I kept it. You cannot get at the underlying anstaz or feature map circuits like you could with the QNNCircuit getters and while I could have passed those back as well I kept it to what the xxxQNN needs which is th circuit and which parameters are used for input and weights. If someone were to need those for any reason they could make their own composition like in fact the example in the docs for SamplerQNN & EstimatorQNN show.
The other aspect I updated is the util method
derive_num_qubits_feature_map_ansatz
in adjust_num_qubits.py. Since it seems to be a public method I altered it so it does either BlueprintCircuit based circuits like it did before, the default, or if you set a new argument to True then it uses the library function equivalents,Evidently any BluePrintCircuit based/using code will need to be removed later but for now it all should work as it did before but code will use the functions where it did not seem to be a compatibility concern as such.