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

[BUG] null.qubit no longer plays nicely with custom operations #5508

Closed
1 task done
obliviateandsurrender opened this issue Apr 12, 2024 · 2 comments · Fixed by #5582
Closed
1 task done

[BUG] null.qubit no longer plays nicely with custom operations #5508

obliviateandsurrender opened this issue Apr 12, 2024 · 2 comments · Fixed by #5582
Labels
bug 🐛 Something isn't working

Comments

@obliviateandsurrender
Copy link
Contributor

obliviateandsurrender commented Apr 12, 2024

Expected behavior

import pennylane as qml
from pennylane.resource.error import ErrorOperation

class IssueErrorOp(ErrorOperation):
    def __init__(self, phase, wires):
        self.phase = phase
        super().__init__(phase, wires=wires)
    def error(self):
        return 1.0

@qml.qnode(qml.device('null.qubit', wires=2))
def circuit():
    IssueErrorOp(1.0, [0])
    return qml.state()

>>> circuit()
[0.0]

null.qubit should allow for adding custom operators to the workflow.

Actual behavior

import pennylane as qml
from pennylane.resource.error import ErrorOperation

class IssueErrorOp(ErrorOperation):
    def __init__(self, phase, wires):
        self.phase = phase
        super().__init__(phase, wires=wires)
    def error(self):
        return 1.0

@qml.qnode(qml.device('null.qubit', wires=2))
def circuit():
    IssueErrorOp(1.0, [0])
    return qml.state()

>>> circuit()
DeviceError: Operator ReplyErrorOp(1.0, wires=[0]) not supported on null.qubit and does not provide a decomposition.

Additional information

This issue exists on the master and possibly comes from using DefaultQubit's preprocess for null.qubit as well.

Source code

No response

Tracebacks

No response

System information

Name: PennyLane
Version: 0.36.0.dev0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages
Editable project location: /Users/utkarsh/Xanadu/Codes/SourceCodes/pennylane
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: amazon-braket-pennylane-plugin, PennyLane-Catalyst, PennyLane-Cirq, PennyLane-qiskit, PennyLane_Lightning, quantum-datasets

Platform info:           macOS-13.6.4-arm64-arm-64bit
Python version:          3.10.4
Numpy version:           1.26.4
Scipy version:           1.12.0
Installed devices:
- default.clifford (PennyLane-0.36.0.dev0)
- default.gaussian (PennyLane-0.36.0.dev0)
- default.mixed (PennyLane-0.36.0.dev0)
- default.qubit (PennyLane-0.36.0.dev0)
- default.qubit.autograd (PennyLane-0.36.0.dev0)
- default.qubit.jax (PennyLane-0.36.0.dev0)
- default.qubit.legacy (PennyLane-0.36.0.dev0)
- default.qubit.tf (PennyLane-0.36.0.dev0)
- default.qubit.torch (PennyLane-0.36.0.dev0)
- default.qutrit (PennyLane-0.36.0.dev0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@obliviateandsurrender obliviateandsurrender added the bug 🐛 Something isn't working label Apr 12, 2024
@albi3ro
Copy link
Contributor

albi3ro commented Apr 12, 2024

I have been wanting to extend null.qubit to be able to able to mimic any other device for their preprocessing. We should potentially allow the submission other sorts of alternate preprocessing too.

@trbromley
Copy link
Contributor

Thanks @obliviateandsurrender! CC @DSGuala.

This looks like a nontrivial problem for use of specs and the Tracker when working with custom error ops.

astralcai added a commit that referenced this issue Apr 26, 2024
**Context:**

**Description of the Change:**

null.qubit will now automatically support any operation that doesn't
have a decomposition.

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

[sc-61258] Fixes #5508

---------

Co-authored-by: Astral Cai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
3 participants