PennyLaneAI / pennylane

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.
https://pennylane.ai
Apache License 2.0
2.27k stars 585 forks source link

[BUG] `qml.qsvt` throws `UnboundLocalError` with `convention = Wx` #6104

Closed KetpuntoG closed 3 weeks ago

KetpuntoG commented 3 weeks ago

Expected behavior

This code should work:

import pennylane as qml

@qml.qnode(qml.device('default.qubit',wires=[0]))
def circ():
  qml.qsvt([1],[0], wires=[0],convention='Wx')
  return qml.state()
circ()

Actual behavior

UnboundLocalError: local variable 'global_phase_op' referenced before assignment

Additional information

Bug found by Jarret, working on the QSVT project

Source code

No response

Tracebacks

No response

System information

Name: PennyLane
Version: 0.38.0.dev17
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, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane-qiskit, PennyLane_Lightning

Platform info:           Linux-6.1.85+-x86_64-with-glibc2.35
Python version:          3.10.12
Numpy version:           1.26.4
Scipy version:           1.13.1
Installed devices:
- qiskit.aer (PennyLane-qiskit-0.37.0)
- qiskit.basicaer (PennyLane-qiskit-0.37.0)
- qiskit.basicsim (PennyLane-qiskit-0.37.0)
- qiskit.ibmq (PennyLane-qiskit-0.37.0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.37.0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.37.0)
- qiskit.remote (PennyLane-qiskit-0.37.0)
- default.clifford (PennyLane-0.38.0.dev17)
- default.gaussian (PennyLane-0.38.0.dev17)
- default.mixed (PennyLane-0.38.0.dev17)
- default.qubit (PennyLane-0.38.0.dev17)
- default.qubit.autograd (PennyLane-0.38.0.dev17)
- default.qubit.jax (PennyLane-0.38.0.dev17)
- default.qubit.legacy (PennyLane-0.38.0.dev17)
- default.qubit.tf (PennyLane-0.38.0.dev17)
- default.qubit.torch (PennyLane-0.38.0.dev17)
- default.qutrit (PennyLane-0.38.0.dev17)
- default.qutrit.mixed (PennyLane-0.38.0.dev17)
- default.tensor (PennyLane-0.38.0.dev17)
- null.qubit (PennyLane-0.38.0.dev17)
- lightning.qubit (PennyLane_Lightning-0.37.0)

Existing GitHub issues

jsmallz333 commented 3 weeks ago

yeah should be able to change line 146 of qsvt.py to 'if global_phase', as wx convention's angle change is already accounted for in standard return of line 148

KetpuntoG commented 3 weeks ago

Done here @jsmallz333 , thanks :)