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

[v0.40.0 QA] PL Docs Improvements #6774

Merged
merged 8 commits into from
Jan 9, 2025
10 changes: 5 additions & 5 deletions doc/development/autograph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Python control flow:

return qml.expval(qml.PauliZ(0) + qml.PauliZ(3))

While this function cannot be captured directly because there is control flow that depends on the function's inputs' values—the inputs are treated as JAX tracers at capture time, which don't have concrete valuesit can be captured by converting to native PennyLane syntax
While this function cannot be captured directly because there is control flow that depends on the values of the function's inputs (the inputs are treated as JAX tracers at capture time, which don't have concrete values) it can be captured by converting to native PennyLane syntax
via AutoGraph. This is the default behaviour of :func:`~.autograph.make_plxpr`.

>>> weights = jnp.linspace(-1, 1, 20).reshape([5, 4])
Expand Down Expand Up @@ -351,7 +351,7 @@ For example, using a ``for`` loop with static bounds to index a JAX array is str
However, indexing within a ``for`` loop with AutoGraph will require that the object indexed is
a JAX array or dynamic runtime variable.

If the array you are indexing within the for loop is not a JAX array
If the array you are indexing within the ``for`` loop is not a JAX array
or dynamic variable, an error will be raised:

>>> @qml.qnode(dev)
Expand All @@ -378,7 +378,7 @@ a JAX array:
>>> eval_jaxpr(plxpr.jaxpr, plxpr.consts)
[Array(0.99500417, dtype=float64)]

If the object you are indexing **cannot** be converted to a JAX array, it is not possible for AutoGraph to capture this for loop.
If the object you are indexing **cannot** be converted to a JAX array, it is not possible for AutoGraph to capture this ``for`` loop.

If you are updating elements of the array, this must be done using the JAX ``.at`` and ``.set`` syntax.

Expand Down Expand Up @@ -440,7 +440,7 @@ However, like with conditionals, a similar restriction applies: variables
which are updated across iterations of the loop must have a JAX compilable
type (Booleans, Python numeric types, and JAX arrays).

You can also utilize temporary variables within a for loop:
You can also utilize temporary variables within a ``for`` loop:

>>> def f(x):
... for y in [0, 4, 5]:
Expand Down Expand Up @@ -520,7 +520,7 @@ To allow AutoGraph conversion to work in this case, simply convert the list to a
>>> eval_jaxpr(plxpr.jaxpr, plxpr.consts)
[Array(0.99500417, dtype=float64)]

If the object you are indexing **cannot** be converted to a JAX array, it is not possible for AutoGraph to capture this for loop.
If the object you are indexing **cannot** be converted to a JAX array, it is not possible for AutoGraph to capture this ``while`` loop.

If you are updating elements of the array, this must be done using the JAX ``.at`` and ``.set`` syntax.

Expand Down
28 changes: 14 additions & 14 deletions pennylane/bose/bosonic_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def binary_mapping(
The mapping procedure is described in equations :math:`27-29` in `arXiv:1507.03271 <https://arxiv.org/pdf/1507.03271>`_.

Args:
bose_operator(BoseWord, BoseSentence): the bosonic operator
n_states(int): maximum number of allowed bosonic states
bose_operator (BoseWord, BoseSentence): the bosonic operator
n_states (int): Maximum number of allowed bosonic states. Defaults to ``2``.
ps (bool): Whether to return the result as a ``PauliSentence`` instead of an
operator. Defaults to ``False``.
wire_map (dict): A dictionary defining how to map the states of
Expand All @@ -61,7 +61,7 @@ def binary_mapping(
tol (float): tolerance for discarding the imaginary part of the coefficients

Returns:
Union[PauliSentence, Operator]: A linear combination of qubit operators
Union[PauliSentence, Operator]: a linear combination of qubit operators

**Example**

Expand Down Expand Up @@ -175,16 +175,16 @@ def unary_mapping(

Args:
bose_operator(BoseWord, BoseSentence): the bosonic operator
n_states(int): maximum number of allowed bosonic states
ps (bool): Whether to return the result as a PauliSentence instead of an
operator. Defaults to False.
n_states(int): Maximum number of allowed bosonic states. Defaults to ``2``.
ps (bool): Whether to return the result as a ``PauliSentence`` instead of an
operator. Defaults to ``False``.
wire_map (dict): A dictionary defining how to map the states of
the Bose operator to qubit wires. If None, integers used to
label the bosonic states will be used as wire labels. Defaults to None.
the Bose operator to qubit wires. If ``None``, integers used to
label the bosonic states will be used as wire labels. Defaults to ``None``.
tol (float): tolerance for discarding the imaginary part of the coefficients

Returns:
Union[PauliSentence, Operator]: A linear combination of qubit operators.
Union[PauliSentence, Operator]: a linear combination of qubit operators

**Example**

Expand Down Expand Up @@ -325,15 +325,15 @@ def christiansen_mapping(

Args:
bose_operator(BoseWord, BoseSentence): the bosonic operator
ps (bool): Whether to return the result as a PauliSentence instead of an
operator. Defaults to False.
ps (bool): Whether to return the result as a ``PauliSentence`` instead of an
operator. Defaults to ``False``.
wire_map (dict): A dictionary defining how to map the states of
the Bose operator to qubit wires. If None, integers used to
label the bosonic states will be used as wire labels. Defaults to None.
the Bose operator to qubit wires. If ``None``, integers used to
label the bosonic states will be used as wire labels. Defaults to ``None``.
tol (float): tolerance for discarding the imaginary part of the coefficients

Returns:
Union[PauliSentence, Operator]: A linear combination of qubit operators.
Union[PauliSentence, Operator]: a linear combination of qubit operators
"""

qubit_operator = _christiansen_mapping_dispatch(bose_operator, tol)
Expand Down
4 changes: 2 additions & 2 deletions pennylane/capture/autograph/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def run_autograph(fn):
).

Args:
fn (Callable): the callable to be converted. This could be a function, a QNode, or another callable object.
For a QNode, the ``Qnode.func`` will be converted. For another callable object, a function calling the
fn (Callable): The callable to be converted. This could be a function, a QNode, or another callable object.
For a QNode, the ``QNode.func`` will be converted. For another callable object, a function calling the
object will be converted.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion pennylane/ops/functions/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def dot(
method (str): The graph colouring heuristic to use in solving minimum clique cover for
grouping, which can be ``'lf'`` (Largest First), ``'rlf'`` (Recursive Largest First),
``'dsatur'`` (Degree of Saturation), or ``'gis'`` (Greedy Independent Set).
This keyword argument is ignored if ``grouping_type`` is ``None``.
This keyword argument is ignored if ``grouping_type`` is ``None``. Defaults to ``'lf'`` if no method is provided.

Raises:
ValueError: if the number of coefficients and operators does not match or if they are empty
Expand Down
2 changes: 1 addition & 1 deletion tests/capture/autograph/test_autograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def circ():
assert jax.core.eval_jaxpr(plxpr.jaxpr, plxpr.consts)[0] == -1

def test_ctrl_op(self):
"""Test that the adjoint of an operator successfully passes through autograph without raising an error"""
"""Test that controlled operators successfully pass through autograph"""

@qml.qnode(qml.device("default.qubit", wires=2))
def circ():
Expand Down
Loading