-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add pasqal device #31
Conversation
@co9olguy, I have a couple of questions you might be able to answer on this PR:
From what I can tell, qubits = [
pasqal.ThreeDGridQubit(0, 0, 0),
pasqal.ThreeDGridQubit(0, 1, 0),
pasqal.ThreeDGridQubit(1, 0, 0),
pasqal.ThreeDGridQubit(1, 1, 0)
]
dev = qml.device("cirq.pasqal", wires=4, shots=1000, analytic=True, qubits=qubits, control_radius=0.1)
@qml.qnode(dev, interface="tf")
def circuit(params):
qml.templates.BasicEntanglerLayers(params, wires=[0, 1, 2, 3])
return qml.expval(qml.PauliZ(0) @ qml.PauliX(2)) works fine for me without the
This one follows from above; it seems that the
The main hurdle I can see though is that This could be done by creating 'pseudo' quantum operation, that the @qml.qnode(dev, interface="tf")
def circuit(params, x, y, z):
pennylane_cirq.move_qubit(x, y, z, wires=0)
qml.templates.BasicEntanglerLayers(params, wires=[0, 1, 2, 3])
return qml.expval(qml.PauliZ(0) @ qml.PauliX(2)) |
Where did you see this? |
I think what happened (forgive me, been a couple weeks) is I eventually figured it out (you need to pass a list of qubits rather than a single qubit object), but I didn't cross that out of my working notes above before posting here @josh146 did you actually evaluate the QNode? 😀 |
The There's no specific validation stopping us from initializing the grid with floats instead, but it might not work end-to-end, since it looks like integers are assumed? It gets confusing though, since the
Almost! Everything seemed to work (applying etc.) until |
Interesting, this looks like a recent change (less than 3 weeks ago). Wonder why? 🤔
Got everything to work now. I just needed to take some time to understand better how Cirq implements things (e.g., |
@josh146 looks like some of the tests are failing because of that cirq versioning bug 😦. Otherwise, this is ready for review. Since it depends on a non-official branch for the moment, I've set up a holding branch. In the end, the implementation didn't need to be very complex at all |
Codecov Report
@@ Coverage Diff @@
## pasqal-holding #31 +/- ##
================================================
Coverage 100.00% 100.00%
================================================
Files 6 7 +1
Lines 222 236 +14
================================================
+ Hits 222 236 +14
Continue to review full report at Codecov.
|
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.
Looks good to me @co9olguy! Ran it locally with TensorFlow, and it works well (if but a little slow):
qubits = [
pasqal.ThreeDGridQubit(0, 0, 0),
pasqal.ThreeDGridQubit(0, 1, 0),
pasqal.ThreeDGridQubit(1, 0, 0),
pasqal.ThreeDGridQubit(1, 1, 0)
]
dev = qml.device("cirq.pasqal", wires=4, qubits=qubits, control_radius=0.1)
@qml.qnode(dev, interface="tf")
def circuit(params):
qml.templates.BasicEntanglerLayers(params, wires=[0, 1, 2, 3])
return qml.expval(qml.PauliZ(0) @ qml.PauliX(2))
params = qml.init.basic_entangler_layers_normal(n_layers=2, n_wires=4)
params = tf.Variable(params)
print(circuit(params))
Only questions/concerns I have are:
-
How we want to proceed with changing the Cirq requirements? Changing the requirement to the fork is required for development/testing, but it could go out of sync with Cirq master. Do we know of a plan to merge the fork back into Cirq master?
-
Documentation: we should add a page
doc/devices/pasqal.rst
, and have a card that links to this indoc/index.rst
. However, the documentation pennylane-cirq.readthedocs.io is currently pinned to latest --- we should change this to stable so that it doesn't appear to users that navigate to the plugin docs.
@@ -1,3 +1,4 @@ | |||
pennylane>=0.9 | |||
cirq>=0.7 | |||
google-api-core[grpc]<=1.14.0 | |||
git+https://github.com/lhenriet/Cirq.git |
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.
How do we want to deal with this requirement when merging into master? The issue I see is that this fork has diverged from Cirq master (it hasn't been kept up to date).
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 keep this in a separate branch, and undocumented, until that fork is successfully merged in. I'll try to keep abreast of when that might happen. In the meantime, we can continue our next steps (developing a tutorial) using the holding branch
def __init__(self, wires, shots=1000, analytic=True, qubits=None, control_radius=1.0): | ||
|
||
if not qubits: | ||
qubits = [pasqal.ThreeDGridQubit(wire, 0, 0) for wire in range(wires)] |
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.
Another future option is to make use of the ThreeDGridQubit
static methods, such as parallelep
and rect
to construct the array of qubits (https://github.com/lhenriet/Cirq/blob/125722761ca56a641db7e15c89303ed55f076441/cirq/pasqal/pasqal_qubits.py#L102)
Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>
* [WIP] Add pasqal device (#31) * adding basic pasqal device * using base simulator and removing qubit worries * adding tests * changes * merge master and fix travis issue * linting * change version * Update pennylane_cirq/pasqal_device.py Co-authored-by: Josh Izaac <[email protected]> * Update pennylane_cirq/pasqal_device.py Co-authored-by: Josh Izaac <[email protected]> * Update pennylane_cirq/pasqal_device.py Co-authored-by: Josh Izaac <[email protected]> Co-authored-by: Josh Izaac <[email protected]> * Update branch (#33) * Update requirements.txt * Update requirements.txt * Update requirements.txt * Update pasqal_device.py * Update test_pasqal_device.py Co-authored-by: Josh Izaac <[email protected]> * change coords * fix * proper attaching of pasqal device * debugging * cleanup and explanation * updates for failing tests * updating requirements to master branch of cirq * ordering test upgrades * fixing more edge cases * Update pennylane_cirq/cirq_device.py * removing print * make identity gates local * Update pennylane_cirq/cirq_device.py Co-authored-by: Josh Izaac <[email protected]> * imports * black * Update format.yml * Update pennylane_cirq/cirq_device.py Co-authored-by: Josh Izaac <[email protected]> * blacker * fixes * docs * more dox * the * Update tests.yml * Update doc/devices/pasqal.rst Co-authored-by: Josh Izaac <[email protected]> * Update tests.yml * Update tests.yml * Update tests.yml Co-authored-by: Josh Izaac <[email protected]>
Adds a new device "cirq.pasqal", which uses the
cirq.pasqal.PasqalDevice
simulator as the execution backend. Cirq should be installed from the following fork: https://github.com/lhenriet/CirqNotes
ThreeDGridQubit
s, which are qubits which have positions in three dimensions.LineQubit
:GridQubit
or theThreeDGridQubit
s needed for thePasqalDevice
, but it would require some small updates to the plugin to support more general cases thanLineQubit
. In particular, I identified that whereverlen
is called on the qubits, it will fail unless the qubits areLineQubit
s.PasqalDevice
also requires an initialization argumentcontrol_radius
. Two qubits in the grid can undergo two-qubit gates iff they are withincontrol_radius
of one anotherWith the addition of better handling for different qubit arrangements, I think we can relatively easily add the
PasqalDevice
.One option for the future is to perhaps expose the positions of the qubits in 3D space as a variable that Pennylane can tune and optimize, but I think it might be tricky at the moment, since it would require updating the qubits after the device is initialized (and I'm not exactly sure whether Cirq/Pasqal supports non-static arrangements yet)