-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
How to deal with removal of BasicAer? #5718
Comments
I checked c1375ff and found following lines that use BasicAer.
|
quantum_info.Operator's way is as follows. I think we can replace BasicAer in Aqua except quantum_instance by making utility functions, e.g., What do you think? from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator, Statevector
from collections import Counter
from random import choices
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
samples=1000
zero = Statevector.from_int(0, 2**qc.num_qubits)
state = zero.evolve(qc)
print('unitary matrix:\n', Operator(qc).data)
print('state vector:', state.to_dict())
prob = state.probabilities_dict()
print('probability:', prob)
print('count:', Counter(choices(list(prob.keys()), list(prob.values()), k=samples)))
print()
# check endian
qc = QuantumCircuit(2)
qc.x(0)
zero = Statevector.from_int(0, 2**qc.num_qubits)
state = zero.evolve(qc)
print('unitary matrix:\n', Operator(qc).data)
print('state vector:', state.to_dict())
prob = state.probabilities_dict()
print('probability:', prob)
print('count:', Counter(choices(list(prob.keys()), list(prob.values()), k=samples))) Output:
|
I tried to replace BasicAer in Aqua and found quantum_info.Operator does not handle We need to think how to deal with such circuits with BasicAer.
|
I was more thinking that QuantumInstance would support using QuantumInfo in the absence of any specific backend being passed in, in a way that allowed the algorithms to still perceive a counts based (qasm simulator) type output or statevector one. Algorithms already only include measurements when using backends such as qasm simulators or real devices. This would then allow any algo to run on Aer and or real backend and if none were provided would use QuantumInfo via the QuantumInstance (maybe with a flag on QuantumInstance to say counts versus statevector). This implicit use of QuantumInfo in QuantumInstance would thus replace the explicit passing of BasicAer as a backend since it will no longer exist. |
I think it's possible to fallback to QuantumInfo if no backend is specified. My PoC code to generate statevector and counts is simple. https://github.com/Qiskit/qiskit-aqua/blob/895d968371c45cea6e44f7a03e3beb8174bd8695/qiskit/aqua/utils/circuit_utils.py#L85 |
My take would be that we do not attempt to add extra logic to support function that is not there in QuantumInfo. If we can avoid using such specifics it might be good. But if not then we could either detect these and alert via an error, which may be unnecessary overhead, or just let them pass through which presumably will result in a different error. Depending on the error we might want to catch/augment it suggest use of Aer etc to run the algorithm in this case. |
I agree. Extending QuantumInfo is not a good strategy. We have to discuss whether Aqua should depend on Aer or not. What do you think of including Aer in requirement.txt? |
Internally in the couple of places where Aqua relies on doing some conversion can we not just always use QuantumInfo. For running an algo, when the user passes a QuantumInstance, if they explicitly give it a backend we would use that, otherwise QuantumInstance would use QuantumInfo (with a flag to choose counts/statevector). I do not see why we would need to include Aer as a hard dependency. |
As for QuantumInstance, your idea makes sense. I'm thinking of circuit_state_fn because it uses |
I agree with Steve in the above, if we can avoid adding objects on our side then that would be great (and no hard Aer dependency). As for Measurements could probably be taken care of inside the Another case we need to keep in mind, is that the operator cannot handle Barriers, but I think we can just remove them before simulation. I think we should talk to Chris to see if that's how the Operator is intended to be used. In principle there are also non-unitary constructs such as the |
Perhaps the issue of the Initialize needs to be brought up then in the Terra Issue that is discussing the BasicAer removal. Clearly that extension will then not work with Terra alone as it is, and require Aer or some other backend having reset, unless something is done. Terra itself treats Aer as optional. If it turns out that the circuit_state_fn has to end up dependent on Aer then we can always still treat Aer as an optional pkg and raise an exception that this logic cannot be used without Aer being installed. |
The comment of Initializer explains as follows. So, I think it is as intended.
I found that circuit_state_fn is the only module that uses the initializer. In my local env, |
Do you have a different version locally that you would expect it to fail the lint for you (lint being run via |
I remembered that |
I found that some gates are converted into another that is equal to the original one up to global phase, e.g., X -> U3(pi,0,pi), and some unit tests fail due to the global phase. |
As a side effect, my PoC finishes unit tests faster than master. master
qiskit-community/qiskit-aqua#1009
|
Just talked to Chris, the removal of the functionality of Note: that just concerns the |
It's a good news. As far as Terra keeps BasicAer, it would be nice keep BasicAer in Aqua too. What do you mean "just concerns the qasm_simulator"? It is easy to generate counts from |
E.g. how would you run this with quantum info?
The main restriction of the |
You are right. |
We had not used conditionals in circuits we created in Aqua in the past. Unless any circuits had these introduced when they became part of the library, from where we now use these, and I do not think they did, I do not think we use these. |
There were no conditionals introduced with the move to the library, so I think no algorithm currently uses them. But in future there might be algos that do, so we probably shouldn't add any restrictions on what can be run or not |
If algos choose to use this in the future it would need to be based on whether the backend supports them or not, as appropriate, since conditional is presently not supported by actual devices. So in that regard there are restrictions that need to be catered to. |
Thank you for all information. As far as real devices don't support conditionals, Aqua don't have to support it either. Otherwise, such quantum algorithms can run with only Aer/BasicAer. I think of the following strategy.
So, how about putting this issue on hold? |
I don't agree. Only because our hardware isn't quite there yet that doesn't mean we cannot test more advanced quantum algorithms. After all, we've been testing large qubit number and circuits w/o decoherence, which hardware doesn't support (yet) 😉 We can always tell users that this won't yet run on actual hardware -- which happens right now already if you try to run conditionals. |
The strategy sounds good. As such we have a plan ready, if we need it. |
In terms of support of various backend capabilities (conditionals or whatever) ideally the algorithms should be built to run and leverage, potentially optionally, any capabilities that would improve their performance/behavior but arguably not at the expense of limiting their ability to run on any backend including real devices where people want to try them out albeit on smaller problems that may fit. Algos currently adapt to qasm or statevector modes and the goal has been to made algorithms more hardware (backend) aware/adaptable in order to improve their outcome. |
Yes, the implementations of the algorithms in Aqua should be able to run on hardware, if possible. We shouldn't introduce artificial limitations by default (like adding conditionals). But if users come up with an algorithm that uses these features that we are able to simulate and will be able to run in future, I don't see why we should disallow this. |
I am not saying to disallow as such. More that it would be preferable if such an algorithm would optionally run, in some alternate manner, such that one can target more backends. Maybe it runs less optimally. If it were such that even for small problems some alternate mode is unrealistic then it maybe that it could only run on certain backends until some future time. I would not see us rejecting such an algo, just preferring that it be more adaptable until that point if possible. |
Algorithms have been refactored over to use primitives - this is no longer relevant at all. As such I am closing this issue. |
What is the expected enhancement?
The removal of BasicAer is under discussion.
#4443
There are some Aqua modules that use BasicAer, e.g., CircuitOp.
It would be good to discuss how to deal with the removal.
The text was updated successfully, but these errors were encountered: