-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate init module #1689
Deprecate init module #1689
Conversation
Hello. You may have forgotten to update the changelog!
|
:class:`Operation <pennylane.operation.Operation>` class. Unless a device knows how to implement this class on a | ||
quantum computer, it queries the operation's ``expand()`` method, which expresses the operation as a | ||
decomposition of other operations. More precisely, this method returns a :class:`tape <pennylane.tape.QuantumTape>` | ||
instance that represents the queue of the decomposition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sneaked in a little overhaul of this and the following file...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually, there is no difference in PennyLane between a template or ansatz and a gate - they are
This is great to have! I have a received a lot of questions regarding the difference lately.
@@ -37,12 +37,13 @@ def apply(func, qnode_collection): | |||
As we are using the ``'torch'`` interface, we now apply ``torch.sum`` | |||
to the QNodeCollection: | |||
|
|||
>>> cost = qml.apply(torch.sum, qnodes) | |||
>>> cost = qml.collections.apply(torch.sum, qnodes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a bug...qml.apply
is now another function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch 😬
>>> | ||
>>> with OperationRecorder() as rec: | ||
>>> qml.templates.layers.StronglyEntanglingLayers(weights, wires=[0, 1]) | ||
>>> qml.templates.StronglyEntanglingLayers(weights, wires=[0, 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cosmetic change...
@@ -485,7 +485,7 @@ def circuit(weights): | |||
qml.templates.StronglyEntanglingLayers(weights, wires=[0, 1]) | |||
return qml.expval(qml.PauliZ(0)) | |||
|
|||
weights = jnp.array(qml.init.strong_ent_layers_normal(n_wires=2, n_layers=2)) | |||
weights = jnp.array(np.random.random(qml.templates.StronglyEntanglingLayers.shape(n_layers=2, n_wires=2))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit convoluted, but random number generation with jax is complicated, so I decided to parse here...
@@ -1430,7 +1430,7 @@ def test_qnode_collection_integration(self): | |||
|
|||
assert qnodes.interface == "tf" | |||
|
|||
weights = tf.Variable(qml.init.strong_ent_layers_normal(n_wires=2, n_layers=2)) | |||
weights = tf.Variable(np.random.random(qml.templates.StronglyEntanglingLayers.shape(n_layers=2, n_wires=2))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use the tf.random.uniform
function but would have to parse to Variable
anyways...
weights = jnp.array(qml.init.strong_ent_layers_normal(n_wires=2, n_layers=2)) | ||
weights = jnp.array( | ||
np.random.random(qml.templates.StronglyEntanglingLayers.shape(n_layers=2, n_wires=2)) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in the following I am creating numpy arrays and parsing them...the reason to not use native jax.random
functions is that some tests compare to data produced with a seed, and they fail in such a case.
Codecov Report
@@ Coverage Diff @@
## master #1689 +/- ##
=======================================
Coverage 99.20% 99.20%
=======================================
Files 201 201
Lines 15080 15121 +41
=======================================
+ Hits 14960 15001 +41
Misses 120 120
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mariaschuld thanks for getting to this so quickly 🚅 looks great from my end!
Only thing to do before merging is to add this deprecation to the changelog
:class:`Operation <pennylane.operation.Operation>` class. Unless a device knows how to implement this class on a | ||
quantum computer, it queries the operation's ``expand()`` method, which expresses the operation as a | ||
decomposition of other operations. More precisely, this method returns a :class:`tape <pennylane.tape.QuantumTape>` | ||
instance that represents the queue of the decomposition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually, there is no difference in PennyLane between a template or ansatz and a gate - they are
This is great to have! I have a received a lot of questions regarding the difference lately.
doc/introduction/templates.rst
Outdated
shape = BasicEntanglerLayers.shape(n_layers=2, n_wires=n_wires) | ||
weights = np.random.random(size=shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really nice!
qml.inv(bell_state_preparation(wires=[0, 1])) | ||
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1)) | ||
def circuit(a, b): | ||
MyTemplate(a, b, wires=range(n_wires)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch
|
||
.. code-block:: python3 | ||
|
||
@qml.template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Probably we should also remove this from the codebase lol (@antalszava)
@@ -8,21 +8,10 @@ Templates | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't visited the template gallery in a while, it's looking really awesome
@@ -37,12 +37,13 @@ def apply(func, qnode_collection): | |||
As we are using the ``'torch'`` interface, we now apply ``torch.sum`` | |||
to the QNodeCollection: | |||
|
|||
>>> cost = qml.apply(torch.sum, qnodes) | |||
>>> cost = qml.collections.apply(torch.sum, qnodes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch 😬
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
…ane into deprecate_init_module
The init module contains simple functions that generate random arrays of the correct dimension for use in templates. This approach was superseded by having the templates define these functions as a class method. But the module is still in the API reference, and may be used in the docs and demos.
This PR adds deprecation warnings to the functions in the init module and replaces its usage in the docs. It also updates the templates docs here and there, because some sections were outdated.
Drawbacks
A separate PR should remove usage in the demos.