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

Add TransformTrace, TransformTracer and TransformInterpreter classes for transforming PLxPR #6389

Draft
wants to merge 174 commits into
base: master
Choose a base branch
from

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Oct 11, 2024

This PR adds 3 new classes to qml.capture to facilitate transforming PLxPR natively without the need to first create QuantumScripts.

  • TransformInterpreter will be used to evaluate PLxPR for the purposes of applying transforms.
  • TransformInterpreter will use TransformTrace and TransformTracer to transform primitives that are being evaluated.
  • Scaffolding needed to create transforms for PLxPR has been added to TransformDispatcher, TransformContainer, and TransformProgram.
  • A markdown file has been added to qml.capture to give a detailed explanation of how the framework for applying transforms natively to PLxPR works.
  • Update qml.capture.enable() and qml.capture.disable() to dispatch to jax when using pennylane classes with capture enabled, and to autograd when capture is disabled. This assumes that users won't be silly and try to use pennylane.numpy with capture enabled.

[sc-75560]

justinpickering and others added 14 commits November 11, 2024 10:15
…mplexWarnings` (#6543)

**Context:**
- This PR addresses a recurring ComplexWarning issue that appears when
using differentiable workflows involving both complex and float types,
particularly during backpropagation. Users have reported this issue (see
an example
[here](https://discuss.pennylane.ai/t/casting-of-complex-to-float-when-using-phaseshift-in-circuit-for-qml/7439)),
and [internal
discussions](https://xanaduhq.slack.com/archives/C0743CNS9E3/p1730329623028289)
have concluded that while the warning is generally harmless, it can
still be confusing for users.

**Description of the Change:**
- A warning note has been added to the Gradients and training page in
the documentation. The note explains the origin of the ComplexWarning,
assures users that it is non-critical in this context, and provides a
code snippet to suppress the warning.

**Benefits:**
- Clarifies to users that the ComplexWarning does not indicate a
calculation error, which can help avoid unnecessary troubleshooting.
- Offers an easy method to suppress the warning

**Possible Drawbacks:**
- Suppressing warnings could potentially hide other, less common issues
involving complex numbers in more advanced workflows
- Users may overlook the warning's informational value if they suppress
it without fully understanding the implications

**Related GitHub Issues:**

---------

Co-authored-by: Mudit Pandey <[email protected]>
…amples (#6544)

**Context:**
- The `qml.AmplitudeEmbedding` docstring examples currently includes an
unnecessary return, `qml.expval(qml.Z(0))`, which isn’t referenced or
needed in the examples. This can confuse users, it adds an extra detail
without contributing to the main purpose of the examples.

**Description of the Change:**
- Removes the unused qml.expval(qml.Z(0)) return statement from all
qml.AmplitudeEmbedding examples

**Benefits:**
- Streamlines example code

**Possible Drawbacks:**
N/A

**Related GitHub Issues:**
**Context:**

Prior to this fix, the `repr` for `Identity` was incorrectly indexing
`self.wires` at zero. This returned incorrect string representations.
```python
>>> repr(qml.I([0, 1, 2, 3])
'I(0)'
```
This was potentially not caught as the `__repr__` method was not being
tested.

After this fix, the entire `self.wires` attribute is being processed.
This returns the intended string representations of the operator,
```python
>>> repr(qml.I([0, 1, 'a', 3])
'I([0,1,'a',3])'
>>> repr(qml.I([0])
'I(0)'
>>> repr(qml.I())
'I()'
```

**Description of the Change:**

1. Corrected the handling of `self.wires` in `Identity.__repr__`.
2. Added a test to `test_identity.py` to make sure the string
representation is accurate.

**Benefits:** Code accuracy and clarity.

**Possible Drawbacks:** N/A

Fixes [sc-77328]

---------

Co-authored-by: Mudit Pandey <[email protected]>
**Context:**

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

---------

Co-authored-by: Andrija Paurevic <[email protected]>
…6521)

**Context:**

As the higher order primitives `for`, `while`, and `cond` get more
feature-rich, especially with the incoming changes for dynamically
shaped arrays, it can be hard to keep track of what order the arguments
come in. This will get harder when we have to add in more positional
arguments for the dynamically shaped array dimensions.

**Description of the Change:**

Updates `for`, `while` and `cond` to store slices into the positionally
arguments instead of numbers of the different types of arguments. Now we
can simply consume:
```
args[provided_slice]
```
instead of having to do:
```
args[some_calcualtion_for_start: some_calculation_for_end]
```

I also rewrote some of the logic in the for conditional to make it
easier to construct all the relevant data.

**Benefits:**

**Possible Drawbacks:**

For the for loop, the slices into the arguments start after the `start,
stop, step` instead of including the offset by three. I wasn't quite
sure which one made more sense.

**Related GitHub Issues:**

[sc-77579]

---------

Co-authored-by: David Wierichs <[email protected]>
Context:

Completing the deprecation cycle of `qml.shadows.shadow_expval`.

Description of the Change:

1. Update deprecations.rst
2. Update changelog-dev.md
3. Remove all deprecated source code

No references found in Catalyst, Lightning or QML.

[sc-77485]

---------

Co-authored-by: lillian542 <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
**Context:**
See EPIC: [[P1] Update PennyLane GitHub repo README content positioning
for
researchers](https://app.shortcut.com/xanaduai/epic/76283/p1-update-content-in-pennylane-github-repository-readme?cf_workflow=500000005&ct_workflow=all&group_by=none)

---------

Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: ixfoduap <[email protected]>
**Context:**

Follow up PR addressing the `-0.01%` project code coverage issue that
slipped through the cracks in #6530.

**Description of the Change:**

Removed the relevant check because it was being exclusively tested by a
removed unit test (associated with `qml.shadows.shadow_expval`),

Here's the old test that was removed which was testing that logic
branch:
```python
...
    def test_non_shadow_error(self):
        """Test that an exception is raised when the decorated QNode does not
        return shadows"""
        dev = qml.device("default.qubit", wires=1, shots=100)

        @partial(qml.shadows.shadow_expval, H=qml.PauliZ(0))
        @qml.qnode(dev)
        def circuit():
            qml.Hadamard(0)
            return qml.expval(qml.PauliZ(0))

        msg = "Tape measurement must be ClassicalShadowMP, got 'ExpectationMP'"
        with pytest.raises(ValueError, match=msg):
            circuit()
...
```

**Benefits:** Better code coverage.

**Possible Drawbacks:** None.

[sc-77485]
Base automatically changed from plxpr-interpreter-base to master November 11, 2024 19:37
@mudit2812 mudit2812 changed the title Add TransformTrace, TransformTracer and TransformTraceInterpreter classes for transforming PLxPR Add TransformTrace, TransformTracer and TransformInterpreter classes for transforming PLxPR Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.