-
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
Extend the basis gates of BasicSimulator #12186
Conversation
One or more of the the following people are requested to review this:
|
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 for the PR @1ucian0, would it make sense to add a few tests to check that the extended support works?
Pull Request Test Coverage Report for Build 8853263480Details
💛 - Coveralls |
if operation.name == "unitary": | ||
qubits = operation.qubits | ||
gate = operation.params[0] | ||
self._add_unitary(gate, qubits) | ||
elif operation.name in ("id", "u0", "delay"): |
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.
I'm not fully sure that delay
is the same as id
in BasicSimulator
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.
Given that BasicSimulator
doesn't understand pulses, I think that the choice is between accepting delay
and treating it as an identity or failing if a circuit contains a delay
. I would vote for accepting it but raising a user warning to err on the side of caution, given that users often don't understand the capabilities of each simulator.
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.
@jakelishman what do you think? Should be delay
be id
, or warning, or not accepted?
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.
The basic simulator is noiseless, and in noiseless quantum-state evolution a time-delay is the identity op. I think it's fine / correct to accept delay and do nothing.
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 @1ucian0 for adding the tests and handling the edge cases. The PR looks good to me, I just have two minor suggestions. One is an inline suggestion about raising a user warning with delay, and the other one would be to include a transpilation step in the run tests, just to make sure that the pass manager runs successfully in case somebody chooses a BasicSimulator as target. I checked out your PR locally and confirmed that it works so this can also be left to a follow-up.
if operation.name == "unitary": | ||
qubits = operation.qubits | ||
gate = operation.params[0] | ||
self._add_unitary(gate, qubits) | ||
elif operation.name in ("id", "u0", "delay"): | ||
pass |
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.
What about a message like this one?
pass | |
if operation.name == "delay": | |
warnings.warn( | |
"BasicSimulator cannot simulate gate durations, " | |
"treating delay operation as an identity.", | |
UserWarning, | |
stacklevel=2, | |
) | |
pass |
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.
I think we're fine without a warning; it's completely valid to simulate a delay as an identity if there's no noise in the system.
In e1ad7cb I added the conversion to target. I feel that checking transpilation is checking too much. If the backend can convert to a target and transpile does something wrong with it, it is a different issue. |
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.
#12186 (comment) testing the target seems fair. I am also not too worried about delay
because I think that treating it as id
is the closest we can get with a statevector simulator (so in any case it isn't wrong in my opinion), so in the interest of time I am going to approve.
ctrl_state: control state expressed as integer, | ||
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s. | ||
ctrl_state: control state expressed as integer, string (e.g.``"110"``), or ``None``. | ||
If ``None``, use all 1s. |
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.
This will have broken the formatting because the continuation line is unindented, and I don't think it'll have actually fixed the problem, which is that there's no space betwen e.g.
and the opening ``
.
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.
let's try in c35b9cf
|
||
if gate == "U": | ||
if gate in ("U", "u"): | ||
gc = gates.UGate | ||
elif gate == "u1": | ||
gc = gates.U1Gate | ||
elif gate == "u2": | ||
gc = gates.U2Gate | ||
elif gate == "u3": | ||
gc = gates.U3Gate | ||
elif gate == "h": | ||
gc = gates.HGate | ||
elif gate == "u": | ||
gc = gates.UGate | ||
elif gate == "p": | ||
gc = gates.PhaseGate |
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.
If we're going to add this many new gates, please can we switch to using a dict lookup to retrieve the gate classes?
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.
done in 5cddee7
if operation.name == "unitary": | ||
qubits = operation.qubits | ||
gate = operation.params[0] | ||
self._add_unitary(gate, qubits) | ||
elif operation.name in ("id", "u0", "delay"): | ||
pass |
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.
I think we're fine without a warning; it's completely valid to simulate a delay as an identity if there's no noise in the system.
upgrade_providers: | ||
- | | ||
The :class:`.BasicSimulator` python-based simulator included in :mod:`qiskit.providers.basic_provider` | ||
now includes all the standard gates (:mod:`qiskit.circuit.library .standard_gates`) up to 3 qubits. The new basis support includes: |
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.
This is maybe a feature rather than an upgrade? Fwiw, I probably wouldn't bother listing all the gates below - "includes all the standard gates in :mod:`qiskit.circuit.library`
" is descriptive enough.
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.
done in e81740e
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.
I think that you have implemented all of @jakelishman's comments, so I will approve again and wait to see if he's got any final remark.
* extend the basis gates of BasicSimulator * remove variational sized gates * reno and test * accidentally missing u2 and u1 * three qubits support * support for parameters * support for all the standard gates upto 3 qubits * test * adding rccx * missing gates * test notes * readjust test * check target * tt * dict lookup * reno
Fixes #10852
The simulator
BasicSimulator
is python-based simulator included inqiskit.providers.basic_provider
. After the discussion in #10673, Qiskit resolved that every standard gate, up to 3 qubits, can be inBasicSimulator
.The new basis support was extended to: ,
ccx
,ccz
,ch
,cp
,crx
,cry
,crz
,cs
,csdg
,cswap
,csx
,cu
,cu1
,cu3
,cx
,cy
,cz
,dcx
,delay
,ecr
,global_phase
,h
,id
,iswap
,measure
,p
,r
,rccx
,reset
,rx
,rxx
,ry
,ryy
,rz
,rzx
,rzz
,s
,sdg
,swap
,sx
,sxdg
,t
,tdg
,u
,u1
,u2
,u3
,unitary
,x
,xx_minus_yy
,xx_plus_yy
,y
, andz
.