Skip to content

Commit

Permalink
Merge branch 'master' into bot/stable-deps-update
Browse files Browse the repository at this point in the history
  • Loading branch information
albi3ro authored Jul 23, 2024
2 parents c7884b5 + 09b0366 commit ffbba6f
Show file tree
Hide file tree
Showing 282 changed files with 6,952 additions and 2,285 deletions.
1 change: 0 additions & 1 deletion .github/workflows/core_tests_durations.json
Original file line number Diff line number Diff line change
Expand Up @@ -13182,7 +13182,6 @@
"ops/op_math/test_composite.py::TestConstruction::test_map_wires[True-expected_overlapping_ops1]": 0.001044666045345366,
"ops/op_math/test_composite.py::TestConstruction::test_ndim_params_raises_error": 0.0008577080443501472,
"ops/op_math/test_composite.py::TestConstruction::test_parameters": 0.0009155830484814942,
"ops/op_math/test_composite.py::TestConstruction::test_queue_idx": 0.0008379160426557064,
"ops/op_math/test_composite.py::TestConstruction::test_raise_error_fewer_than_2_operands": 0.0010355000267736614,
"ops/op_math/test_composite.py::TestConstruction::test_tensor_and_hamiltonian_converted": 0.0014357499894686043,
"ops/op_math/test_composite.py::TestMscMethods::test_copy[ops_lst0]": 0.0009615410235710442,
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/install_deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inputs:
tensorflow_version:
description: The version of TensorFlow to install for any job that requires TensorFlow
required: false
default: 2.16
default: 2.16.0
install_pytorch:
description: Indicate if PyTorch should be installed or not
required: false
Expand Down Expand Up @@ -95,6 +95,11 @@ runs:
python setup.py bdist_wheel
pip install dist/PennyLane*.whl
- name: Install Catalyst
shell: bash
if: inputs.install_catalyst_after_pennylane == 'true'
run: pip install --upgrade pennylane-catalyst

- name: Install PennyLane-Lightning master
shell: bash
if: inputs.install_pennylane_lightning_master == 'true'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/interface-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ jobs:
install_jax: true
install_tensorflow: true
install_pytorch: false
# This is required during the release process when the latest released version of
# catalyst requires the latest version of pennylane that is about to be released.
# Installing catalyst after pennylane to make sure that the latest catalyst is used.
install_catalyst_after_pennylane: true
# using lightning master does not work for the tests with external libraries
install_pennylane_lightning_master: false
pytest_coverage_flags: ${{ inputs.pytest_coverage_flags }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ on:
required: false
type: string
default: ''
install_catalyst_after_pennylane:
description: Indicate if the latest Catalyst should be installed after PennyLane
required: false
type: boolean
default: false
install_pennylane_lightning_master:
description: Indicate if PennyLane-Lightning should be installed from the master branch
required: false
Expand Down Expand Up @@ -147,6 +152,7 @@ jobs:
install_tensorflow: ${{ inputs.install_tensorflow }}
install_jax: ${{ inputs.install_jax }}
additional_pip_packages: ${{ inputs.additional_pip_packages }}
install_catalyst_after_pennylane: ${{ inputs.install_catalyst_after_pennylane }}
install_pennylane_lightning_master: ${{ inputs.install_pennylane_lightning_master }}
requirements_file: ${{ inputs.requirements_file }}

Expand Down
Binary file added doc/_static/templates/prepselprep/prepselprep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 59 additions & 45 deletions doc/code/qml_debugging.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
.. role:: html(raw)
:format: html

qml.debugging
=============

.. automodapi:: pennylane.debugging
:no-heading:
:no-inherited-members:
:skip: PLDB
:skip: pldb_device_manager
This module contains functionality for debugging quantum programs on simulator devices.

:html:`<div class="summary-table">`

.. autosummary::
:nosignatures:

~pennylane.breakpoint
~pennylane.debug_expval
~pennylane.debug_probs
~pennylane.debug_state
~pennylane.debug_tape
~pennylane.snapshots

:html:`</div>`


Entering the Debugging Context
------------------------------
Expand All @@ -17,6 +31,7 @@ the circuit operations are applied. The functionality is highlighted by the exam
circuit below.

.. code-block:: python
:linenos:
import pennylane as qml
Expand All @@ -36,7 +51,7 @@ circuit below.
circuit(1.2345)
Running the above python script opens up the interactive ``[pldb]:`` prompt in the terminal.
Running the above python script opens up the interactive ``[pldb]`` prompt in the terminal.
When this code reaches ``qml.breakpoint()`` it will pause and launch an interactive
debugging prompt. The prompt specifies the path to the script and the next line to be
executed after the breakpoint:
Expand All @@ -45,29 +60,29 @@ executed after the breakpoint:
> /Users/your/path/to/script.py(7)circuit()
-> qml.Hadamard(wires=0)
[pldb]:
[pldb]
Controlling Code Execution in the Debugging Context
---------------------------------------------------

The Pennylane Debugger (PLDB) is built from the native python debugger (Pdb), as such
The Pennylane Debugger (PLDB) is built on top of the native python debugger (PDB). As such,
it shares a similar interface. We can interact with the debugger using the
builtin commands: ``list``, ``longlist``, ``next``, ``continue``, and ``quit``. Any
variables defined in the scope of the quantum function can also be accessed from the
built-in commands such as ``list``, ``longlist``, ``next``, ``continue``, and ``quit``. Any
variables defined within the scope of the quantum function can also be accessed from the
debugger.

.. code-block:: console
[pldb]: print(x)
[pldb] print(x)
1.2345
The ``list`` (and ``longlist``) command will print a section of code around the
breakpoint, highlighting the next line to be executed. This can be used to determine
the location of execution in the circuit.
the location of the execution in the circuit.

.. code-block:: console
[pldb]: longlist
[pldb] longlist
3 @qml.qnode(qml.device('default.qubit', wires=(0,1,2)))
4 def circuit(x):
5 qml.breakpoint()
Expand All @@ -83,14 +98,14 @@ the location of execution in the circuit.
15 return qml.sample()
The ``next`` command will execute the next line of code, and print the following
line to be executed, e.g., the next operation to execute is ``CNOT``.
line to be executed. In this example, the next operation to execute is the ``CNOT``.

.. code-block:: console
[pldb]: next
[pldb] next
> /Users/your/path/to/script.py(8)circuit()
-> qml.CNOT(wires=(0,2))
[pldb]: list
[pldb] list
3 @qml.qnode(qml.device('default.qubit', wires=(0,1,2)))
4 def circuit(x):
5 qml.breakpoint()
Expand All @@ -103,16 +118,16 @@ line to be executed, e.g., the next operation to execute is ``CNOT``.
12
13 qml.breakpoint()
Alternative, the ``continue`` command allows for jumping between breakpoints. This command resumes
code execution until the next breakpoint is reached. Finally, the ``quit`` command
ends the debugging prompt.
Alternatively, the ``continue`` command allows for jumping between breakpoints. This command resumes
code execution until the next breakpoint is reached, or termination if there is none. Finally,
the ``quit`` command ends the debugging prompt and terminates the execution altogether.

.. code-block:: console
[pldb]: continue
[pldb] continue
> /Users/your/path/to/script.py(14)circuit()
-> qml.RX(-x, wires=1)
[pldb]: list
[pldb] list
9
10 for w in (0, 1, 2):
11 qml.RX(2*x, wires=w)
Expand All @@ -123,25 +138,24 @@ ends the debugging prompt.
16
17 circuit(1.2345)
[EOF]
[pldb]: quit
[pldb] quit
Extracting Circuit Information
------------------------------

While in the debugging prompt, we can extract information and perform measurements
on the qunatum circuit. Specifically we can make measurements using
:func:`~pennylane.debug_expval`, :func:`~pennylane.debug_state`,
:func:`~pennylane.debug_probs`, and access the gates in the circuit using
:func:`~pennylane.debug_tape`.
While in the debugging prompt, we can extract information about the current contents
of the quantum tape using :func:`~pennylane.debug_tape`. We can also perform measurements dynamically
on the quantum circuit using :func:`~pennylane.debug_expval`, :func:`~pennylane.debug_state`,
and :func:`~pennylane.debug_probs`.

Consider the circuit from above,

.. code-block:: console
> /Users/your/path/to/script.py(7)circuit()
-> qml.Hadamard(wires=0)
[pldb]: longlist
[pldb] longlist
3 @qml.qnode(qml.device('default.qubit', wires=(0,1,2)))
4 def circuit(x):
5 qml.breakpoint()
Expand All @@ -155,24 +169,24 @@ Consider the circuit from above,
13 qml.breakpoint()
14 qml.RX(-x, wires=1)
15 return qml.sample()
[pldb]: next
[pldb] next
> /Users/your/path/to/script.py(8)circuit()
-> qml.CNOT(wires=(0,2))
[pldb]: next
[pldb] next
> /Users/your/path/to/script.py(10)circuit()
-> for w in (0, 1, 2):
[pldb]:
[pldb]
All of the operations applied so far are tracked in the circuit's ``QuantumTape``
which is accessible using :func:`~pennylane.debug_tape`. This can be used to
*visually* debug the circuit.

.. code-block:: console
[pldb]: qtape = qml.debug_tape()
[pldb]: qtape.operations
[pldb] qtape = qml.debug_tape()
[pldb] qtape.operations
[Hadamard(wires=[0]), CNOT(wires=[0, 2])]
[pldb]: print(qtape.draw())
[pldb] print(qtape.draw())
0: ──H─╭●─┤
2: ────╰X─┤
Expand All @@ -182,41 +196,41 @@ for the wires of interest can be probed using :func:`~pennylane.debug_probs`.

.. code-block:: console
[pldb]: qml.debug_state()
[pldb] qml.debug_state()
array([0.70710678+0.j, 0. +0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0.70710678+0.j, 0. +0.j, 0. +0.j])
[pldb]: qml.debug_probs(wires=(0,2))
[pldb] qml.debug_probs(wires=(0,2))
array([0.5, 0. , 0. , 0.5])
Another method for probing the system is by measuring observables via
:func:`~pennylane.debug_expval`.

.. code-block:: console
[pldb]: qml.debug_expval(qml.Z(0))
[pldb] qml.debug_expval(qml.Z(0))
0.0
[pldb]: qml.debug_expval(qml.X(0)@qml.X(2))
[pldb] qml.debug_expval(qml.X(0) @ qml.X(2))
0.9999999999999996
Additionally, the quantum circuit can be dynamically updated by adding gates directly
from the prompt. This allows users to modify the circuit *on-the-fly*!

.. code-block:: console
[pldb]: continue
[pldb] continue
> /Users/your/path/to/script.py(14)circuit()
-> qml.RX(-x, wires=1)
[pldb]: qtape = qml.debug_tape()
[pldb]: print(qtape.draw(wire_order=(0,1,2)))
[pldb] qtape = qml.debug_tape()
[pldb] print(qtape.draw(wire_order=(0,1,2)))
0: ──H─╭●──RX─┤
1: ────│───RX─┤
2: ────╰X──RX─┤
[pldb]: qml.RZ(0.5*x, wires=0)
[pldb] qml.RZ(0.5*x, wires=0)
RZ(0.61725, wires=[0])
[pldb]: qml.CZ(wires=(1,2))
[pldb] qml.CZ(wires=(1,2))
CZ(wires=[1, 2])
[pldb]: qtape = qml.debug_tape()
[pldb]: print(qtape.draw(wire_order=(0,1,2)))
[pldb] qtape = qml.debug_tape()
[pldb] print(qtape.draw(wire_order=(0,1,2)))
0: ──H─╭●──RX──RZ─┤
1: ────│───RX─╭●──┤
2: ────╰X──RX─╰Z──┤
23 changes: 16 additions & 7 deletions doc/code/qml_noise.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ quantum circuit. One can construct standard Boolean functions using the followin
~wires_eq
~wires_in

For example, a Boolean function that checks of an operation is on wire ``0`` can be created
like so:
For example, a Boolean function that checks if an operation is on wire ``0`` can be created
as follows:

>>> fn = wires_eq(0)
>>> fn = qml.noise.wires_eq(0)
>>> op1, op2 = qml.PauliX(0), qml.PauliX(1)
>>> fn(op1)
False
>>> fn(op2)
True

>>> fn(op2)
False

Arbitrary Boolean functions can also be defined by wrapping the functional form
of custom conditions with the following decorator:

Expand All @@ -79,7 +80,7 @@ with a maximum parameter value:
def rx_condition(op, **metadata):
return isinstance(op, qml.RX) and op.parameters[0] < 1.0
Boolean functions can be combined using standard bit-wise operators, such as
Boolean functions can be combined using standard bitwise operators, such as
``&``, ``|``, ``^``, or ``~``. The result will be another Boolean function. It
is important to note that as Python will evaluate the expression in the order
of their combination, i.e., left to right, the order of composition could matter,
Expand Down Expand Up @@ -117,6 +118,7 @@ For example, a constant-valued over-rotation can be created using:
>>> rx_constant = qml.noise.partial_wires(qml.RX(0.1, wires=[0]))
>>> rx_constant(2)
RX(0.1, 2)

>>> qml.NoiseModel({rx_condition: rx_constant})
NoiseModel({
BooleanFn(rx_condition): RX(phi=0.1)
Expand Down Expand Up @@ -177,7 +179,7 @@ above, such as :func:`~.op_eq`. These objects do not need to be instantiated dir
~WiresEq
~WiresIn

Bitwise operations like `And` and `Or` are represented with the following classes in the
Bitwise operations like ``And`` and ``Or`` are represented with the following classes in the
:mod:`boolean_fn` module:

.. currentmodule:: pennylane.boolean_fn
Expand All @@ -193,8 +195,15 @@ Bitwise operations like `And` and `Or` are represented with the following classe
Class Inheritence Diagram
^^^^^^^^^^^^^^^^^^^^^^^^^

Note all child classes inherit from the same parent :class:`~.BooleanFn`,
but are just located in different modules.

**Noise Conditionals:**

.. inheritance-diagram:: pennylane.noise.conditionals
:parts: 1

**Boolean Fn conditionals:**

.. inheritance-diagram:: pennylane.boolean_fn
:parts: 1
13 changes: 13 additions & 0 deletions doc/code/qml_pytrees.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
qml.pytrees
===========

.. currentmodule:: pennylane.pytrees

.. warning::

Unless you are a PennyLane or plugin developer, you likely do not need
to use these functions.

.. automodapi:: pennylane.pytrees
:no-heading:
:include-all-objects:
Loading

0 comments on commit ffbba6f

Please sign in to comment.