Comments (10)
Yes, importing should be consistent. While importing the vanilla of numpy should cause no issues if gradients are not involved, we will want users to get used to the pattern of importing the wrapped openqml version. For this reason, we should establish (and hold ourselves) to a solid standard of always importing the wrapped version.
from pennylane.
The only place where it should be safe to import vanilla numpy is the plugins - as the plugins simply provide the device 'black box' that is used by autograd, nothing that takes place inside the plugins should affect the automatic differentiation.
from pennylane.
Like Josh said the plugins do not interact with autograd in any way, which is why I think they should import the standard numpy. The docs can make it clear that the users should always import numpy from openqml, but we also need to explain why (and when) this needs to be done.
from pennylane.
Okay, let's formalize it as follows:
- All files within OpenQML core must import NumPy from Autograd.
- Users must import NumPy from OpenQML core.
- Plugin developers import standard NumPy for their plugin, and OpenQML core NumPy for their examples.
from pennylane.
@smite, since the submodules ops
and expectation
are part of OpenQML core, do you see any issues if we change the files contained to import NumPy from autograd?
from pennylane.
It's a bit complicated. In the case you mention importing autograd.numpy
instead of numpy
should be safe (but also unnecessary, since autograd should never see the Heisenberg matrices built using it) (they are used inside QNode
and Operation
, and as a hack in the SF plugin).
The downside of using autograd.numpy
when it is not actually necessary is that it may in theory contain bugs that are not present in numpy proper.
One way to handle this is to use autograd.numpy
inside OpenQML for now, and when we have a comprehensive arsenal of tests for different autograd use cases, start replacing instances of autograd.numpy
with numpy
inside OpenQML until a test breaks, thus identifying the places where it is actually required.
So I agree with points 2. and 3., and feel ambivalent towards 1. :)
from pennylane.
A revised set of rules, in that case:
OpenQML Core/Base:
- All top level modules in OpenQML core must import NumPy from Autograd.
- All submodules in OpenQML core (such as
ops
andexpectation
) should import vanilla NumPy. This is assuming all submodules are 'black-boxes' to Autograd.
Users:
- Users must import NumPy from OpenQML core.
Plugin developers:
- Plugin developers import standard NumPy for their plugin, and OpenQML core NumPy for their examples.
from pennylane.
The tests of openqml and openqml core should probably also import numpy from OpenQML core as the tests should mimic what is happening when the code us used by users? Looking into tests/default.py
this currently does not seem to be the case...
from pennylane.
Yes, that makes sense
from pennylane.
I went through in 2da52ae and checked whether our imports follow the above rules, and made changes when they do not.
In the end:
- I removed
np
altogether fromvariable.py
(unused) - updated
test_default_qubit.py
andtest_default_gaussian.py
to import the openqml version of numpy - decided to leave the vanilla
numpy
version in bothoptimize.py
(this will allow users to differentiate through gradient descent steps -- an atypical but not unheard of usage) anddefault.py
(therenumpy
was only used in our custom assert statements
from pennylane.
Related Issues (20)
- [BUG] Jitting `Projector` gives `ValueError` HOT 6
- [BUG] Error Installing pennylane-lightning[gpu] in conda environment HOT 1
- [BUG] Loading hybrid quantum neuronal networks does not work with TensorFlow HOT 3
- [BUG] Gradient of QPE circuit returns None for Tensorflow HOT 1
- Add unary iteration circuits with associated option for SELECT oracles
- [BUG] Incorrect optimal sector in qubit tapering HOT 4
- [BUG] Restore ability to have observables returning types other than float HOT 4
- [Bug] Equal check for `Sum` objects does not work with string valued wires
- [Bug] Wire order changes in PauliSentence for string-valued wires HOT 1
- [BUG] Declare incompatibility with pennylane-lightning versions HOT 6
- Update documentation on devices/plugins HOT 2
- [BUG] Using from_qiskit is broken in v0.34 HOT 1
- [BUG] pennylane.wires.WireError: Cannot run circuit(s) on default.qubit as they contain wires not found on the device: HOT 8
- [Bug] qml.equal return False unexpectedly
- [BUG] Drawer failing in controlled operations HOT 3
- [BUG] Changing the coefficients makes `TrotterProduct` fail HOT 2
- Ability to count number of executions of a device HOT 5
- [BUG] tensorflow autograph with device derivatives and more than one measurement
- [BUG] Tensorflow type promotion error with `default.mixed` HOT 2
- [BUG] TypeError when simply importing in a Jupyter notebook 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.