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

Solves Issue #1316: Implement an option to print out instructions in the null device #1346

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

smml1996
Copy link

Context: The PennyLane plugin should have an Boolean option print_instructions (other names can also be proposed) with a default False value. This option must forwarded to the C++ device constructor. In the runtime plugin, the QuantumDevice should be able to print out the instructions when the option is set to True:

Description of the Change: The PennyLane plugin now has a boolean option print_instructions with a default value False.
If this option is set to True and we have generated the intermediate code using a null device, then executing the circuit prints out the instructions mentioned in Issue #1316 .

Benefits: allows to visualize and confirm the instructions we have called in a circuit that uses the null device. We can now print instructions by simply compiling the circuit and by passing the flag set set to True (E.g. jitted_circ = qjit(circ_circuit, print_instructions=False)).

Possible Drawbacks: Printing some matrices can take a lot of space.

Related GitHub Issues: #1316

Copy link
Contributor

@dime10 dime10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @smml1996, thank you for submitting your PR!

Overall this looks really nice, good work! I left a few review comments below.

Btw, don't forget to include your name as a contributor in the changelog. This PR can be considered a new feature.

runtime/tests/Test_InstructionStrBuilder.cpp Outdated Show resolved Hide resolved
runtime/tests/Test_InstructionStrBuilder.cpp Outdated Show resolved Hide resolved
runtime/tests/Test_InstructionStrBuilder.cpp Outdated Show resolved Hide resolved
runtime/tests/Test_InstructionStrBuilder.cpp Outdated Show resolved Hide resolved
runtime/tests/Test_InstructionStrBuilder.cpp Show resolved Hide resolved
runtime/lib/backend/null_qubit/NullQubit.hpp Outdated Show resolved Hide resolved
runtime/lib/backend/null_qubit/NullQubit.hpp Outdated Show resolved Hide resolved
runtime/lib/backend/null_qubit/InstructionStrBuilder.hpp Outdated Show resolved Hide resolved
runtime/lib/backend/null_qubit/InstructionStrBuilder.hpp Outdated Show resolved Hide resolved
@smml1996
Copy link
Author

smml1996 commented Dec 1, 2024

Hi @smml1996, thank you for submitting your PR!

Overall this looks really nice, good work! I left a few review comments below.

Btw, don't forget to include your name as a contributor in the changelog. This PR can be considered a new feature.

Awesome!! I added it this commit b3df667 (and fixed a missing line here 4c82c8d)

@smml1996
Copy link
Author

smml1996 commented Dec 1, 2024

I am not sure how to fix this issue from CodeFactor. I do not see any blank line at the end of the block code. How can I fix it?

@dime10
Copy link
Contributor

dime10 commented Dec 2, 2024

I am not sure how to fix this issue from CodeFactor. I do not see any blank line at the end of the block code. How can I fix it?

Oh weird, sometimes CodeFactor is bugged. You can ignore it! : )

@dime10
Copy link
Contributor

dime10 commented Dec 2, 2024

This PR looks fantastic! There is one open comment, other than that once the merge conflict is resolved I'll approve the CI run to confirm tests are passing and we can consider this PR completed 💪

@smml1996
Copy link
Author

smml1996 commented Dec 2, 2024

I have realized that for some reason I was not handling properly zero coefficients in the real part for the string representation of complex numbers. I have fixed it here 5ea6b8e

@dime10
Copy link
Contributor

dime10 commented Dec 2, 2024

I have realized that for some reason I was not handling properly zero coefficients in the real part for the string representation of complex numbers. I have fixed it here 5ea6b8e

Nice! Are you able to resolve the merge conflict so we can test the CI ? :)

@smml1996
Copy link
Author

smml1996 commented Dec 2, 2024

I have realized that for some reason I was not handling properly zero coefficients in the real part for the string representation of complex numbers. I have fixed it here 5ea6b8e

Nice! Are you able to resolve the merge conflict so we can test the CI ? :)

Sure!

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 3.80623% with 278 lines in your changes missing coverage. Please review.

Project coverage is 78.29%. Comparing base (1472b4d) to head (a5f7c30).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...e/lib/backend/null_qubit/InstructionStrBuilder.hpp 0.00% 136 Missing ⚠️
runtime/lib/backend/null_qubit/NullQubit.hpp 0.00% 85 Missing ⚠️
runtime/tests/Test_InstructionStrBuilder.cpp 0.00% 57 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1346      +/-   ##
==========================================
- Coverage   80.79%   78.29%   -2.51%     
==========================================
  Files          73       75       +2     
  Lines        8104     8372     +268     
  Branches      839      893      +54     
==========================================
+ Hits         6548     6555       +7     
- Misses       1502     1763     +261     
  Partials       54       54              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@dime10 dime10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @smml1996! You can consider this PR completed 🎉

@smml1996
Copy link
Author

smml1996 commented Dec 3, 2024

Thank you @smml1996! You can consider this PR completed 🎉

Awesome!!! I see the coverage test did not passed though. Should I try to improve my tests?

@dime10
Copy link
Contributor

dime10 commented Dec 3, 2024

I see the coverage test did not passed though. Should I try to improve my tests?

That's because your tests call the string builder functionality as unit tests, which is great! It does leave the lines uncovered in the device itself (if(print) { ... }), but from side I'm happy with the tests as they are.

@smml1996
Copy link
Author

smml1996 commented Dec 3, 2024

I see the coverage test did not passed though. Should I try to improve my tests?

That's because your tests call the string builder functionality as unit tests, which is great! It does leave the lines uncovered in the device itself (if(print) { ... }), but from side I'm happy with the tests as they are.

Ahh ok! great then! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants