dwavesystems / dwave-gate Goto Github PK
View Code? Open in Web Editor NEWdwave-gate is a software package for constructing, modifying and running quantum circuits on the provided state-vector simulator.
License: Apache License 2.0
dwave-gate is a software package for constructing, modifying and running quantum circuits on the provided state-vector simulator.
License: Apache License 2.0
Currently there is not an easy way to retrieve a qubit added by label. E.g.
c = Circuit()
c.add_qubit("q1")
it would be nice to be able to do
q2 = c.add_qubit("q2")
Greetings D-Wave team,
Hope all are well. I am quite new to this module, and I am trying to see how one can prepare an arbitrary state using dwave.gate
. I can see that you can use .set_state
(if I recall the method name correctly), but it doesn't show the algorithm used for creating the circuit to prepare the state.
Can you kindly point me to where this is explored?
At some point we'll want to connect dwave-gate to the annealing part of Ocean.
We could start simply by implementing a QPU-driven MinimumEigensolver
.
from dwave.gate import Circuit, Qubit
from dwave.gate.operations import SWAP
c = Circuit(1)
q2 = Qubit("q2")
with c.context as reg:
q1 = reg[0]
SWAP([q1, q2])
currently raises
ValueError: Qubit '<qubit: q2, id:q0dt>' not in circuit.
it would be nice if the qubit would be automatically added to the circuit.
Additional Considerations
This might end up adding too much complication, the error message is already super clear so the current behavior make sense as well.
The numpy==1.22.4 requirement seems incompatible with Python 3.7:
ERROR: No matching distribution found for numpy==1.22.4
Should this repo not support 3.7 (we say Python versions >=3.7 are supported for Ocean) or update to something like numpy==1.21.6; python_version < '3.8'
(did not test if compatible with other packages used in this repo)?
Greetings dear D-Wave team,
Hope you are well. So, I am having a bit of an issue with the simulator. It doesn't represent the small values like 0.002 amplitudes, which basically when used with algorithms like FRQI, makes it output a numpy array of all 0s. Anything I can do to fix this?
Here's what I get with Cirq for instance :
[0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.1221966 0.12381981 0.125 0.125 0.125
0.125 0.125 0.12480307 0.11370273 0.125 0.125
0.125 0.125 0.125 0.12498055 0.1087806 0.125
0.125 0.125 0.125 0.125 0.125 0.11108285
0.12499628 0.125 0.125 0.125 0.125 0.125
0.12250098 0.12246352 0.125 0.125 0.125 0.125
0.125 0.125 0.10999145 0.12485503 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.0263247
0.01713632 0. 0. 0. 0. 0.
0.0070138 0.05192965 0. 0. 0. 0.
0. 0.00220521 0.06157745 0. 0. 0.
0. 0. 0. 0.05732016 0.00096478 0.
0. 0. 0. 0. 0.02486988 0.02505364
0. 0. 0. 0. 0. 0.
0.05938755 0.00601839 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
And here's what I get with D-Wave :
[0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. ]
You see the difference? This is causing my code to break as you can imagine. Is there a way I can fix this? Again, this is only in D-Wave, I tried the code with Qiskit, Cirq, TKET, and PennyLane, and they are running as expected, and can extract these smaller values. I'd appreciate the help on fixing this.
I don't think sharing the code would help really, since I am just passing a large circuit. I believe the issue is with the number of digits the simulator can generate for the result (I think it's limited to three digits?). Kindly let me know if you absolutely would need the code, and I will see if I can make a toy example to reproduce this.
Greetings dear D-Wave team,
Hope all are well. How can I draw a circuit to visually confirm if a gate is applied correctly? I have been using the circuit.circuit
for now, but I think there's either an issue with the ParametricOperation
, or with how it is printed :
circuit = Circuit(5, 5)
for i in range(3):
with circuit.context as (q, c):
RX(np.pi, q[i]).conditional([q[3], q[4]])
circuit.unlock()
I get this output, but I don't imagine it is correct :
[<ParametricOperation: RX([3.141592653589793]), qubits=(<qubit: '0', id: q03k>,)>,
<ParametricOperation: RX([3.141592653589793]), qubits=(<qubit: '1', id: q07v>,)>,
<ParametricOperation: RX([3.141592653589793]), qubits=(<qubit: '2', id: q0vz>,)>]
For your kind reference, I am trying to implement a multi-controlled RX gate.
Currently, looping over the basis states is not done in parallel, see
The reason is that supporting OMP in Python wheels is non-trivial because it requires the user to have omp installed. We should investigate using C++ parallel execution.
In [1]: from dwave.gate import Qubit
In [2]: q = Qubit("a")
In [3]: str(q)
Out[3]: '<qubit: a, id:q0px>'
note the spacing between qubit: a
and id:q0px
.
Also, because labels can be arbitrary hashables, you might consider using repr()
for the label, to disambiguate between label=1
and label='1'
I would be nice to be able to do something like
with circuit.context as register:
q1 = register.bylabel("q1")
Additional Considerations
I believe that labels can be duplicated, so would need to handle that case somehow.
rot_circuit = ParametricCircuit(1)
with rot_circuit.context as (p, q, c):
ops.RZ(p[0], q[0])
ops.RY(p[1], q[0])
ops.RZ(p[2], q[0])
...
MyRotOperation([3 * np.pi / 2, np.pi / 2, np.pi], q[2])
As Andrew Berkeley pointed out in a meeting yesterday, it might be nice to allow named parameters. I'm not sure of the best interface for this, but here's some slightly rambly thoughts.
Defining the parametric circuit already uses syntactic sugar; that can be extended through __getattr__
:
#maximum sweetness
circuit = ParametricCircuit(1)
with rot_circuit.context as (p, q, c):
ops.RZ(p.dz0, q[0])
ops.RY(p.dy, q[0])
ops.RZ(p.dz1, q[0])
#less sugar
circuit = ParametricCircuit(1)
with rot_circuit.context as (p, q, c):
ops.RZ(p['dz0'], q[0])
ops.RY(p['dy'], q[0])
ops.RZ(p['dz1'], q[0])
Applying the operator then suffers a bit -- named parameters must follow positional arguments. We can work around this by providing a dict
:
MyRotOperation(dict(dz0=3 * np.pi / 2, dy=np.pi / 2, dz1=np.pi), q[2])
But the circuit definition does not forbid a mix of positional and named operations! If support named parameters is a popular idea, I might suggest not supporting the notation above, nor the extant
MyRotOperation([3 * np.pi / 2, np.pi / 2, np.pi], q[2])
Rather than expect an array of parameters and allow the application of the operator in the same call, we could force the user to curry the parameters separately:
#positional only
MyRotOperation(3 * np.pi / 2, np.pi / 2, np.pi)(q[2])
#named only
MyRotOperation(dz0=3 * np.pi / 2, dy=np.pi / 2, dz1=np.pi)(q[2])
#mixed named and positional
MyRotOperation(3 * np.pi / 2, np.pi / 2, dz1=np.pi)(q[2])
Now, if we do want to forbid the mix of named and positional arguments, we could take an optional parameter:
# list of params
rot_circuit = ParametricCircuit(1) #default: params=list
rot_circuit = ParametricCircuit(1, params=list) #explicit
with rot_circuit.context as (p, q, c):
ops.RZ(p[0], q[0])
ops.RY(p[1], q[0])
ops.RZ(p[2], q[0])
...
MyRotOperation([3 * np.pi / 2, np.pi / 2, np.pi], q[2])
#dict of params
circuit = ParametricCircuit(1, params=dict)
with rot_circuit.context as (p, q, c):
ops.RZ(p.dz0, q[0])
ops.RY(p.dy, q[0])
ops.RZ(p.dz1, q[0])
...
MyRotOperation({'dz0': 3 * np.pi / 2, 'dy': np.pi / 2, 'dz1': np.pi}, q[2])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.