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

Fix tape_expand.py documentation examples #6812

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pennylane/transforms/tape_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def create_decomp_expand_fn(custom_decomps, dev, decomp_depth=None):

.. code-block:: python

def custom_cnot(wires):
def custom_cnot(wires, **_):
return [
qml.Hadamard(wires=wires[1]),
qml.CZ(wires=[wires[0], wires[1]]),
Expand Down Expand Up @@ -358,7 +358,7 @@ def _create_decomp_preprocessing(custom_decomps, dev, decomp_depth=None):

.. code-block:: python

def custom_cnot(wires):
def custom_cnot(wires, **_):
return [
qml.Hadamard(wires=wires[1]),
qml.CZ(wires=[wires[0], wires[1]]),
Expand Down Expand Up @@ -435,7 +435,7 @@ def set_decomposition(custom_decomps, dev, decomp_depth=None):

.. code-block:: python

def custom_cnot(wires):
def custom_cnot(wires, **_):
return [
qml.Hadamard(wires=wires[1]),
qml.CZ(wires=[wires[0], wires[1]]),
Expand All @@ -458,10 +458,12 @@ def circuit():
0: ─╭●─┤ <Z>
1: ─╰X─┤

Now let's set up a context where the custom decomposition will be applied:
Now let's set up a context where the custom decomposition will be applied.
To see our change, the circuit is drawn at the device level where the
custom decomposition will be applied.

>>> with qml.transforms.set_decomposition({qml.CNOT : custom_cnot}, dev):
... print(qml.draw(circuit, wire_order=[0, 1])())
... print(qml.draw(circuit, level="device")())
0: ────╭●────┤ <Z>
1: ──H─╰Z──H─┤

Expand Down
Loading