Use this topic to ask your questions about the PennyLane Challenge: Returning expectation values.
@CatalinaAlbornoz Hi.
For the rotation and expectation value I have the following code but keep getting the error: Runtime Error. ‘numpy.float64’ object has no attribute ‘numpy’
qml.RY(angle, wires=0)
return qml.expval(qml.PauliX(0))
In the run function for testing if I remove .numpy() the test cases pass but obviously I cant do that on the website so Im a bit confused on what to do.
def run(test_case_input: str) -> str:
angle = json.loads(test_case_input)
output = simple_circuit(angle).numpy()
return str(output)
Hello @james111garcia
Thank you for noticing this. It may have been caused by the most recent PennyLane upgrade. We’ll fix it in the backend
Cheers,
Alvaro
Thank you, I also noticed it in Returning Tensor Product Observables and A Shor Thing, there may be more im not sure.
Hi,
I have faced the same issue in more than one challenge.
a quick fix would be to switch back the result to a tensor.
For example:
return np.tensor(qml.expval(...))
Hi @AmineTrabelsi, welcome to the Forum and thanks for the suggestion!
@james111garcia thanks for mentioning these other challenges. We’ll make sure to fix them.
I hope you’re both enjoying the challenges.