I was trying to do those challenges on the PennyLane website and for the one called “States and probabilities” I get this error:
Running on public test set Test 1 of 2 failed! 🚫 Input: [1.23, 4.56] Expected output: [0.2829251572359589, 0.3841937063262924, 0.1411749135148633, 0.1917062229228854] Failure message: Runtime Error: Failed to execute run() function: 'ProbabilityMP' object has no attribute 'tolist'. Test 2 of 2 failed! 🚫 Input: [7.89, 0.12] Expected output: [0.48026161094775754, 0.001733099740534947, 0.5161427069791757, 0.0018625823325319265] Failure message: Runtime Error: Failed to execute run() function: 'ProbabilityMP' object has no attribute 'tolist'. Running on private test set One or more private tests failed. Try again! 🚫
The code I submitted was the following:
# Create a default.qubit device with 2 qubits / wires using qml.device dev = qml.device('default.qubit', wires = 2) # Turn your circuit into a QNode def circuit(angles): """ The quantum circuit that you will simulate. Args: angles (list(float)): The gate angles in the circuit. Returns: (numpy.tensor): The probability vector of the underlying quantum state that this circuit produces. """ # Put the rotation gates here qml.RY(angles, wires = 0) qml.RY(angles, wires = 1) return qml.probs(wires=[0, 1]) # These functions are responsible for testing the solution. def run(test_case_input: str) -> str: angles = json.loads(test_case_input) output = circuit(angles).tolist() return str(output) def check(solution_output: str, expected_output: str) -> None: solution_output = json.loads(solution_output) expected_output = json.loads(expected_output) assert np.allclose(solution_output, expected_output, rtol=1e-4)
I am not sure where the error is coming from. I noticed that the test calls the tolist() method on the output, but I think the problem is in my code. Does anyone know how I could fix it?