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] qml.equal does not work with qml.GlobalPhase #5498

Closed
1 task done
KetpuntoG opened this issue Apr 11, 2024 · 0 comments · Fixed by #5562
Closed
1 task done

[BUG] qml.equal does not work with qml.GlobalPhase #5498

KetpuntoG opened this issue Apr 11, 2024 · 0 comments · Fixed by #5562
Labels
bug 🐛 Something isn't working

Comments

@KetpuntoG
Copy link
Contributor

Expected behavior

qml.equal(qml.PauliX(0)@qml.GlobalPhase(np.pi), qml.PauliX(0)@qml.GlobalPhase(np.pi))

This should be true

Actual behavior

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[<ipython-input-16-74827f3d67e3>](https://hmoo5kikp7-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20240408-060136_RC00_622797729#) in <cell line: 1>()
----> 1 qml.equal(qml.PauliX(0)@qml.GlobalPhase(np.pi), qml.PauliX(0)@qml.GlobalPhase(np.pi))

4 frames
[/usr/local/lib/python3.10/dist-packages/pennylane/ops/op_math/prod.py](https://hmoo5kikp7-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20240408-060136_RC00_622797729#) in _swappable_ops(op1, op2, wire_map)
    545     wires2 = set(wires2)
    546     # compare strings of wire labels so that we can compare arbitrary wire labels like 0 and "a"
--> 547     return False if wires1 & wires2 else str(wires1.pop()) > str(wires2.pop())
    548 
    549 

KeyError: 'pop from an empty set'

Additional information

if I specify the wires in GlobalPhase, it works

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: /usr/local/lib/python3.10/dist-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane_Lightning

Platform info:           Linux-6.1.58+-x86_64-with-glibc2.35
Python version:          3.10.12
Numpy version:           1.25.2
Scipy version:           1.11.4
Installed devices:
- lightning.qubit (PennyLane_Lightning-0.35.1)
- 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)
- null.qubit (PennyLane-0.36.0.dev0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@KetpuntoG KetpuntoG added the bug 🐛 Something isn't working label Apr 11, 2024
albi3ro added a commit that referenced this issue Apr 24, 2024
**Context:**

Operators that don't have any wires (`GlobalPhase` and `Identity`) are
newer additions that don't have full feature coverage in all places.
This can lead to some logic that is unable to handle them.

**Description of the Change:**

Allows `Sum._sort` and `Prod._sort` to work with operators that don't
have any wires.

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

Fixes #5498 [sc-61115]
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
Development

Successfully merging a pull request may close this issue.

1 participant