Certificate Challenge: Introduction to PennyLane

I’m getting wrong probabilities and the subsequent error:

Failure message: Assertion Error: Something isn't quite right with the trainable block..

I can’t quite understand where am I going wrong with the trainable block. My circuit seems to be correct too:

Edit: Fixed it! The last CNOT in the trainer block was switched with source and target.

Hi @essa, welcome to the Forum!

Congratulations on solving the challenge! Remember to accept your certificate in your account settings and share it on LinkedIn.

Note: I’ve blurred your circuit and solution so that others don’t get a spoiler.

@essa nevermind I was able to do it.

Hi @CatalinaAlbornoz , what could be the reason of this. I don’t understand.
Screenshot from 2024-08-30 18-16-35

Hi @baudoin,

This happens when your solution doesn’t work for all valid inputs. Private tests are secret and they’re used to ensure that your solution actually works as expected for any valid input. So for example if you tweak you solution to work only for the inputs in the public tests, your code might fail for other inputs such as the private ones.

You’re probably close to the answer if you already got your code to work for the public tests. You can make up your own test scenarios of input vs expected output to keep improving and testing your solution! This can help you find where you can improve your code.

I hope this helps and good luck with the challenge!

I’m trying to solve this challenge but I get this error:

Blockquote
Running submission…

	Running on public test set

		Test 1 of 2 failed! 🚫
			Input: [[[[0.62832, 0.3927, 1.0472, 0.7854],[0.7854, 0.31416, 0.62832, 0.5236]],[[0.31416, 0.7854, 0.7854, 0.3927],[0.31416, 0.3927, 0.31416, 0.3927]]],"PauliY", 0.5236]
			Expected output: [0.68594, 0.31406]
			Solution output: null
			Failure message: Runtime Error: Failed to execute run() function: _expand_transform_param_shift() got an unexpected keyword argument 'level'.

		Test 2 of 2 failed! 🚫
			Input: [[[[1.0472, 0.7854, 3.1416, 0.3927],[1.0472, 0.7854, 3.1416, 0.5236]],[[1.0472, 0.7854, 1.5708, 0.3927],[0.7854, 0.7854, 1.5708, 0.7854]]],"PauliX", 0.7854]
			Expected output: [0.46653, 0.53347]
			Solution output: null
			Failure message: Runtime Error: Failed to execute run() function: _expand_transform_param_shift() got an unexpected keyword argument 'level'.


	Running on private test set

			One or more private tests failed. Try again! 🚫

Hi @pabloramosdev,

Welcome to the forum!

It looks like your solution isn’t correct.
In your particular case it looks like you’re using the word ‘level’ somewhere in your solution and this is causing the error.

Keep trying and you’ll succeed with the challenge!

If you’re stuck make sure to check the Codebook, the documentation, and the examples available at pennylane.ai.

Hi @CatalinaAlbornoz,

Thank you for your reply. I fixed the solution and finally I succeeded the challenge! :smile:

1 Like

can you give me a hint why my circuit gives the wrong probabilites. the W and S layers pass the test.

Hi @gab , welcome to the Forum!

Your W layer doesn’t look right. If you look closely at the instructions you’ll note that all of the RY gates are applied before all of the CNOT gates for each layer. In your case it looks like all of the RY and CNOT layers are alternating which is not the same.

From the image you shared it’s hard to know whether your implementation for S is correct or not.

Give the challenge a new try and you’ll surely succeed!

How could I miss that? :man_facepalming: Thank you for pointing out.

1 Like

No problem!
Missing these details is more common than you may think.

Good luck with the challenge!

Hi there! I’ve almost completed the challenge, but am having issues with defining my device. My code passes the public tests when I set my device to 4 qubits. I am not sure how this can be made dynamic to pass all of the private tests.

So far, I have been defining the number of qubits within my functions based on the length of params[0] (for the W block) or param_set[0][0] (for the quantum_model circuit). However, these cannot be used to specify the number of qubits outside of the functions, as these matrices are not accessible prior to when the device needs to be defined. What could I try to make a device with the correct number of qubits?