`qml.fourier.coefficients` won't work with more than one expectation value
See original GitHub issueIssue description
When I try to calculate the Fourier coefficients with the new module qml.fourier
if the circuit has more than one measurement an error appears.
Code:
import pennylane as qml
from pennylane import numpy as np
from pennylane.fourier import coefficients
dev = qml.device('default.qubit', wires=2)
@qml.qnode(dev)
def simple_circuit(x):
qml.RX(x[0], wires=0)
qml.RY(x[0], wires=1)
qml.CNOT(wires=[1, 0])
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
coeffs = coefficients(simple_circuit, 1, 2)
print(np.round(coeffs, decimals=4))
Output:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
<ipython-input-111-8c2ae78fdea3> in <module>
13
14
---> 15 coeffs = coefficients(simple_circuit, 1, 2)
16 print(np.round(coeffs, decimals=4))
~/.local/lib/python3.8/site-packages/pennylane/fourier/coefficients.py in coefficients(f, n_inputs, degree, lowpass_filter, filter_threshold)
154 """
155 if not lowpass_filter:
--> 156 return _coefficients_no_filter(f, n_inputs, degree)
157
158 if filter_threshold is None:
~/.local/lib/python3.8/site-packages/pennylane/fourier/coefficients.py in _coefficients_no_filter(f, n_inputs, degree)
228
229 # fill discretized function array with value of f at inpts
--> 230 f_discrete[tuple(nvec)] = f(sample_points)
231
232 coeffs = np.fft.fftn(f_discrete) / f_discrete.size
ValueError: setting an array element with a sequence.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
qml.fourier.coefficients — PennyLane 0.27.0 documentation
Computes the first 2d+1 Fourier coefficients of a 2π periodic function, where d is the highest desired frequency (the degree) of the Fourier...
Read more >arXiv:2211.03101v1 [quant-ph] 6 Nov 2022
We focus our analysis on simple QML models with two and three qubits and observe that increasing the number of parameterized and entangling ......
Read more >pennylane Changelog - pyup.io
JAX-JIT support for computing the gradient of QNodes that return a single vector of probabilities or multiple expectation values is now available.
Read more >qml/tutorial_expressivity_fourier_series.py at master - GitHub
features simply generalize to multi-dimensional Fourier series. ... of consecutive integer-valued frequencies up to degree :math:`r`.
Read more >Generalization in quantum machine learning from few training ...
Our work injects new hope into the field of QML, ... Then, given ρout, one measures the expectation value of a task-specific Hermitian ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure!, I will.
@PCesteban let us know if you pick up anything else, your feedback is very valuable!