Skip to content

Commit

Permalink
Merge rc into master (#1849)
Browse files Browse the repository at this point in the history
* extend the changelog item of the init module deprecation (#1833)

* add sorting to `get_parameters`

* undo accidental direct push to v0.19.0-rc0

* Remove template decorator from PennyLane functions (#1808) (#1835)

* Remove template decorator.

* Correct import and changelog.

* Change interferometer.

* Update pennylane/templates/broadcast.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update doc/releases/changelog-dev.md

Co-authored-by: antalszava <antalszava@gmail.com>

* Update pennylane/templates/broadcast.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update from review.

* More import removed.

* Update parametric ops.

* Update pennylane/templates/subroutines/arbitrary_unitary.py

Co-authored-by: antalszava <antalszava@gmail.com>

Co-authored-by: antalszava <antalszava@gmail.com>

Co-authored-by: Romain <rmoyard@gmail.com>

* Update `QNGOptimizer` to handle deprecations (#1834)

* pass approx option in QNG if need be

* convert to array instead of list; add recwarn to QNG test case

* Update pennylane/optimize/qng.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* add expval(H) with two input params test case

* deprecate diag_approx keyword for QNGOptimizer

* format

* docstring

* changelog

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Sorted `tape.get_parameters` (#1836)

* sorted `get_parameters`

* adapt PR count

* fix metric tensor tests

* also sort in `set_parameters`

* Fix bug to ensure qml.math.dot works in autograph mode (#1842)

* Fix bug to ensure qml.math.dot works in autograph mode

* changelog

Co-authored-by: antalszava <antalszava@gmail.com>

* Update `expand_fn` (rc) (#1838)

* expand_fn

* changes just as in master

* new lines

* Ensure that the correct version of keras is installed for TensorFlow CI (#1847)

* Ensure that the correct version of keras is installed for TensorFlow CI (#1847)

* changelog

Co-authored-by: dwierichs <davidwierichs@gmail.com>
Co-authored-by: Romain <rmoyard@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
  • Loading branch information
4 people authored Nov 4, 2021
1 parent 997d0a2 commit 4229f22
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions doc/releases/changelog-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,9 @@

<h3>Breaking changes</h3>

* Fixes a bug where `qml.math.dot` failed to work with `@tf.function` autograph mode.
[(#1842)](https://github.com/PennyLaneAI/pennylane/pull/1842)

- The operator attributes `has_unitary_generator`, `is_composable_rotation`,
`is_self_inverse`, `is_symmetric_over_all_wires`, and
`is_symmetric_over_control_wires` have been removed as attributes from the
Expand Down
6 changes: 3 additions & 3 deletions pennylane/math/multi_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ def dot(tensor1, tensor2):
return np.tensordot(x, y, dims=[[-1], [-2]], like=interface)

if interface == "tensorflow":
if x.ndim == 0 and y.ndim == 0:
if len(np.shape(x)) == 0 and len(np.shape(y)) == 0:
return x * y

if y.ndim == 1:
if len(np.shape(y)) == 1:
return np.tensordot(x, y, axes=[[-1], [0]], like=interface)

if x.ndim == 2 and y.ndim == 2:
if len(np.shape(x)) == 2 and len(np.shape(y)) == 2:
return x @ y

return np.tensordot(x, y, axes=[[-1], [-2]], like=interface)
Expand Down
5 changes: 2 additions & 3 deletions pennylane/tape/tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,12 @@ def get_parameters(self, trainable_only=True, **kwargs): # pylint:disable=unuse
[0.432, 0.543, 0.133]
"""
params = []
iterator = self.trainable_params if trainable_only else self._par_info
iterator = sorted(self.trainable_params) if trainable_only else self._par_info

for p_idx in iterator:
op = self._par_info[p_idx]["op"]
op_idx = self._par_info[p_idx]["p_idx"]
params.append(op.data[op_idx])

return params

def set_parameters(self, params, trainable_only=True):
Expand Down Expand Up @@ -855,7 +854,7 @@ def set_parameters(self, params, trainable_only=True):
[4, 1, 6]
"""
if trainable_only:
iterator = zip(self.trainable_params, params)
iterator = zip(sorted(self.trainable_params), params)
required_length = self.num_params
else:
iterator = enumerate(params)
Expand Down
14 changes: 14 additions & 0 deletions tests/math/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,20 @@ def test_matrix_matrix_product(self, t1, t2):
res = fn.dot(t1, t1)
assert fn.allequal(res, np.array([[7, 10], [15, 22]]))

def test_matrix_vector_product_tensorflow_autograph(self):
"""Test that the matrix-matrix dot product of two vectors results in a matrix
when using TensorFlow autograph mode"""
t1, t2 = tf.Variable([[1, 2], [3, 4]]), tf.Variable([6, 7])

@tf.function
def cost(t1, t2):
return fn.dot(t1, t2)

with tf.GradientTape() as tape:
res = cost(t1, t2)

assert fn.allequal(res, [20, 46])

multidim_product_data = [
[
np.array([[[1, 2], [3, 4], [-1, 1]], [[5, 6], [0, -1], [2, 1]]]),
Expand Down
2 changes: 1 addition & 1 deletion tests/transforms/test_metric_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def layer2_off_diag_second_order(x, y, z, h, g, f):
qml.RY(y, wires=1)
qml.RZ(z, wires=2)
non_parametrized_layer(a, b, c)
return qml.expval(qml.Hermitian(np.kron(Z, Y), wires=[2, 1]))
return qml.expval(qml.PauliY(1) @ qml.PauliZ(2))

layer2_off_diag_second_order = qml.QNode(layer2_off_diag_second_order, dev)

Expand Down

0 comments on commit 4229f22

Please sign in to comment.