Skip to content
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

Few docstring updates in prep for v0.22.0 #2311

Merged
merged 13 commits into from
Mar 14, 2022
2 changes: 1 addition & 1 deletion pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def expand_matrix(base_matrix, wires, wire_order):
... [3., 4.]], requires_grad=True)
>>> res = expand_matrix(base_matrix_torch, wires=["b"], wire_order=["a", "b"])
>>> type(res)
<class 'torch.Tensor'>
torch.Tensor
>>> res.requires_grad
True
"""
Expand Down
9 changes: 4 additions & 5 deletions pennylane/transforms/batch_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ def circuit(inputs, weights):
qml.RY(weights[1], wires=1)
return qml.expval(qml.PauliZ(1))

>>> x = np.random.uniform(0,1,(10,2))
>>> x.requires_grad = False
>>> w = np.random.uniform(0,1,2)
>>> x = tf.random.uniform((10, 2), 0, 1)
>>> w = tf.random.uniform((2,), 0, 1)
>>> circuit(x, w)
<tf.Tensor: shape=(10,), dtype=float64, numpy=
array([0.17926078, 0.7480163 , 0.47816999, 0.50381628, 0.349178 ,
0.17511444, 0.03769436, 0.19180259, 0.75867188, 0.55335748])>
array([0.46230079, 0.73971315, 0.95666004, 0.5355225 , 0.66180948,
0.44519553, 0.93874261, 0.9483197 , 0.78737918, 0.90866411])>
"""
parameters = tape.get_parameters(trainable_only=False)

Expand Down
16 changes: 9 additions & 7 deletions pennylane/transforms/commutation_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def circuit(x, y, z):
the form ``(ID, CommutationDAGNode)``:

>>> nodes = dag.get_nodes()
[(0, <pennylane.transforms.commutation_dag.CommutationDAGNode object at 0x132b03b20>), ...]
>>> nodes
NodeDataView({0: <pennylane.transforms.commutation_dag.CommutationDAGNode object at 0x7f461c4bb580>, ...}, data='node')

You can also access specific nodes (of type :class:`~.CommutationDAGNode`) by using the :meth:`~.get_node`
method. See :class:`~.CommutationDAGNode` for a list of available
Expand Down Expand Up @@ -205,7 +206,8 @@ def simplify_rotation(rot):


def simplify_controlled_rotation(crot):
r"""Simplify a general one qubit controlled rotation into CRX, CRY, CRZ and CH.
r"""Simplify a general one qubit controlled rotation into CRX, CRY, CRZ and
controlled-Hadamard.

Args:
crot (pennylane.CRot): One qubit controlled rotation.
Expand Down Expand Up @@ -286,8 +288,8 @@ def simplify_u3(u3):
def simplify(operation):
r"""Simplify the (controlled) rotation operations :class:`~.Rot`,
:class:`~.U2`, :class:`~.U3`, and :class:`~.CRot` into one of
:class:`~.RX`, :class:`~.CRX`, :class:`~.RY`, :class:`~.CRY`, :class:`~.`RZ`,
:class:`~.CZ`, :class:`~.H` and :class:`~.CH` where possible.
:class:`~.RX`, :class:`~.CRX`, :class:`~.RY`, :class:`~.CRY`, :class:`~.RZ`,
:class:`~.CZ`, :class:`~.Hadamard` and controlled-Hadamard where possible.

Args:
operation (.Operation): Rotation or controlled rotation.
Expand Down Expand Up @@ -755,10 +757,10 @@ def _merge_no_duplicates(*iterables):
"""Merge K list without duplicate using python heapq ordered merging.

Args:
*iterables: A list of k sorted lists
*iterables: A list of k sorted lists.

Yields:
Iterator: List from the merging of the k ones (without duplicates)
Iterator: List from the merging of the k ones (without duplicates).
"""
last = object()
for val in heapq.merge(*iterables):
Expand Down Expand Up @@ -897,7 +899,7 @@ def get_node(self, node_id):
return self._multi_graph.nodes(data="node")[node_id]

def get_nodes(self):
"""Return iterable to loop through all the nodes in the DAG
"""Return iterable to loop through all the nodes in the DAG.

Returns:
networkx.classes.reportviews.NodeDataView: Iterable nodes.
Expand Down
2 changes: 1 addition & 1 deletion pennylane/transforms/qcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def contract_tensors(

The network can then be contracted using:

>>> qml.transforms.contract_tensors(tensors, graph, prep, meas)
>>> qml.transforms.qcut.contract_tensors(tensors, graph, prep, meas)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

38
"""
# pylint: disable=import-outside-toplevel
Expand Down