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] Documentation examples on pennylane.fourier.qnode_spectrum no longer work #6593

Open
1 task done
justinpickering opened this issue Nov 15, 2024 · 0 comments
Open
1 task done
Assignees
Labels
bug 🐛 Something isn't working documentation 📘 Documentation changes and updates

Comments

@justinpickering
Copy link
Contributor

Expected behavior

I expect to be able to run all the examples in the pennylane.fourier.qnode_spectrum https://docs.pennylane.ai/en/stable/code/api/pennylane.fourier.qnode_spectrum.html examples.

Actual behavior

Examples in the documentation should be fully executable, and not provide any errors.

Additional information

No response

Source code

n_qubits = 3
dev = qml.device("default.qubit", wires=n_qubits)

@qml.qnode(dev)
def circuit(x, y, z, w):
    for i in range(n_qubits):
        qml.RX(0.5*x[i], wires=i)
        qml.Rot(w[0,i,0], w[0,i,1], w[0,i,2], wires=i)
        qml.RY(2.3*y[i], wires=i)
        qml.Rot(w[1,i,0], w[1,i,1], w[1,i,2], wires=i)
        qml.RX(z, wires=i)
    return qml.expval(qml.Z(0))

x = np.array([1., 2., 3.])
y = np.array([0.1, 0.3, 0.5])
z = -1.8
w = np.random.random((2, n_qubits, 3))
print(qml.draw(circuit)(x, y, z, w))

res = qml.fourier.qnode_spectrum(circuit, argnum=[0, 1, 2])(x, y, z, w)
for inp, freqs in res.items():
    print(f"{inp}: {freqs}")

Tracebacks

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-a66971ae3a6a> in <cell line: 24>()
     22 print(qml.draw(circuit)(x, y, z, w))
     23 
---> 24 res = qml.fourier.qnode_spectrum(circuit, argnum=[0, 1, 2])(x, y, z, w)
     25 for inp, freqs in res.items():
     26     print(f"{inp}: {freqs}")

6 frames
/usr/local/lib/python3.10/dist-packages/numpy/core/numeric.py in within_tol(x, y, atol, rtol)
   2330     def within_tol(x, y, atol, rtol):
   2331         with errstate(invalid='ignore'), _no_nep50_warning():
-> 2332             return less_equal(abs(x-y), atol + rtol * abs(y))
   2333 
   2334     x = asanyarray(a)

ValueError: operands could not be broadcast together with shapes (27,3) (3,3)

System information

Name: PennyLane
Version: 0.39.0
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_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:
- lightning.qubit (PennyLane_Lightning-0.39.0)
- default.clifford (PennyLane-0.39.0)
- default.gaussian (PennyLane-0.39.0)
- default.mixed (PennyLane-0.39.0)
- default.qubit (PennyLane-0.39.0)
- default.qutrit (PennyLane-0.39.0)
- default.qutrit.mixed (PennyLane-0.39.0)
- default.tensor (PennyLane-0.39.0)
- null.qubit (PennyLane-0.39.0)
- reference.qubit (PennyLane-0.39.0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@justinpickering justinpickering added bug 🐛 Something isn't working documentation 📘 Documentation changes and updates labels Nov 15, 2024
@dwierichs dwierichs self-assigned this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working documentation 📘 Documentation changes and updates
Projects
None yet
Development

No branches or pull requests

2 participants