Code Monkey home page Code Monkey logo

dwave-gate's People

Contributors

arcondello avatar thisac avatar wbernoudy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dwave-gate's Issues

State Preparation in dwave.gate

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?

Consider adding unknown qubits to a circuit automatically

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.

Support for Py3.7?

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)?

Simulator accuracy

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.

Drawing circuits

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.

Inconsistent spacing when printing qubits

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'

Bikeshedding: accept named parameters in ParametricCircuit

From 3_parametric_circuits.py

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])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.