Comments (4)
Seconded!
from pennylane.
I'm in two minds about this. On the one hand, qm.Gate(p1, p2) | [wire1, wire2]
is easier to parse/read, and is close to the style of Strawberry Fields and ProjectQ.
However, in the 'spirit'(?) of OpenQML, I would personally prefer to keep the syntax as 'pythonic' as we could, without overloading operators with a more commonly known use - a beginner or someone with a
a computer science/software engineering background would be more familiar with the 'bitwise or' behaviour of |
, and would likely not recognise the pseudo-braket notation. By keeping everything as a function call and avoiding custom operator definitions, it is similar in style to NumPy np.func(..., axis=[1,2])
, SciPy, TensorFlow, and OpenFermion (of.Hubbard(operators=...)
).
(Avoiding the |
syntax in OpenQML also helps keep the library quantum assembly language agnostic when working with other industry partners with their own quantum assembly language, otherwise it might appear we are co-opting Blackbird.)
An alternative third approach would be to use an operator that currently does not have any explicit action on standard Python objects. Since we are targeting only Python 3.5+ with OpenQML, we could use the @
operator, which invokes the __matmul__()
method:
def circuit(weights):
qm.Gate(weights) @ [wire1, wire2]
Another thing to be considered - assuming we choose to overload an operator, do we make explicit wire
objects, analogous to the RegRef
of Strawberry Fields? Or simply act the gate on a list of integers? I'm inclined to suggest just a list/tuple of integers in version 0.1, to avoid additional code complexity.
from pennylane.
I would use a list of ints to refer to subsystems/wires for simplicity, since there's no need for the extra functionality provided by the RegRefs.
I think I'd prefer |
over the @
operator just because it avoids syntax proliferation (|
is used not only in Blackbird but also in ProjectQ, so we cannot really be accused of pushing our own conventions, we joined an existing "standard"). I don't think operator overloading is a problem in itself, it's relatively common and easy to explain it in the docs. In Python __or__
is only defined for ints, so there shouldn't be much room for error.
Lastly and least importantly, since @
is matrix multiplication, semantically it may be a bit misleading since [w1, w2] does not represent a ket vector but a subsystem reference?
from pennylane.
As @josh146 mentioned, the design philosophy of openqml is to be as close to numpy/tensorflow/scipy etc as possible, with the goal of making things more accessible for ML-only people to give it a shot.
We will stick with the standard pythonic way of calling ops, without overloading any operators
from pennylane.
Related Issues (20)
- PennyLane Torch Implementation Question HOT 16
- Issue when using batched data on StronglyEntanglingLayers template.[BUG] HOT 3
- [BUG] `sum_expand` producing incorrect result dimensions
- [BUG] lighthing.qubit torch layer batch size issue HOT 1
- [BUG] Specs does not take into account transforms HOT 7
- How to support Prod observables in custom devices? HOT 3
- [BUG] Can't differentiate `dynamic_one_shot` with `autograd` and `jax` HOT 1
- [BUG] `dynamic_one_shot` does not work with TensorFlow HOT 1
- [BUG] CNOT decomposes to CNOT
- [BUG] Some decompositions/transforms do not preserve derivatives HOT 1
- [BUG] `defer_measurements` does not work with `qml.cond` applied to controlled gates HOT 3
- Define `BasisStateProjector.compute_sparse_matrix` HOT 3
- [BUG] `KerasLayer` has unintended side effects on its QNode HOT 1
- [BUG] Documentation generated does not show the parameters for subclasses of Operation. HOT 1
- Add support for Quantum ESPRESSO HOT 2
- [BUG] `QuantumScript.map_to_standard_wires` sometimes returns original tape HOT 2
- [CHORE] Update `docs/requirements.txt` to reduce package bloat
- [BUG] Differentiation does not work with `dynamic_one_shot` HOT 1
- [BUG] Different ground states when batching with vmap or calling the function directly HOT 5
- Add `PrepSelPrep` block encoding template HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pennylane.