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")
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.
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.
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 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
.
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)?
For Python 3.12 (3.12.1 on my system, Ubuntu 24.04 LTS) building from source fails
For Python 3.11, you can build as follows (as described in README):
git clone [email protected]:JoelPasvolsky/dwave-gate.git
pip install -r requirements.txt # includes installing cgen
make install
but in Python 3.12
pip install -r requirements.txt
ERROR: Exception:
Traceback (most recent call last):
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 180, in exc_logging_wrapper
status = run_func(*args)
^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 248, in wrapper
return func(self, options, args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 377, in run
requirement_set = resolver.resolve(
^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 92, in resolve
result = self._result = resolver.resolve(
^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 397, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _add_to_criteria
if not criterion.candidates:
^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_vendor/resolvelib/structs.py", line 156, in __bool__
return bool(self._sequence)
^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in __bool__
return any(self)
^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 47, in _iter_built
candidate = func()
^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 206, in _make_candidate_from_link
self._link_candidate_cache[link] = LinkCandidate(
^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 293, in __init__
super().__init__(
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 156, in __init__
self.dist = self._prepare()
^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 225, in _prepare
dist = self._prepare_distribution()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 304, in _prepare_distribution
return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 538, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 653, in _prepare_linked_requirement
dist = _get_prepared_distribution(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 69, in _get_prepared_distribution
abstract_dist.prepare_distribution_metadata(
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py", line 48, in prepare_distribution_metadata
self._install_build_reqs(finder)
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py", line 118, in _install_build_reqs
build_reqs = self._get_build_requires_wheel()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py", line 95, in _get_build_requires_wheel
return backend.get_requires_for_build_wheel()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_internal/utils/misc.py", line 697, in get_requires_for_build_wheel
return super().get_requires_for_build_wheel(config_settings=cs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 166, in get_requires_for_build_wheel
return self._call_hook('get_requires_for_build_wheel', {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 321, in _call_hook
raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Traceback (most recent call last):
File "/home/joel/Work/dwave_gate_3_12_1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
obj = import_module(mod_path)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joel/.pyenv/versions/3.12.1/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 994, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/tmp/pip-build-env-abi8mgtv/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 10, in <module>
import distutils.core
ModuleNotFoundError: No module named 'distutils'
if you just try the make you'd get ModuleNotFoundError: No module named 'cgen'
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.
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'
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.
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.