Skip to content

Conversation

gzemlevskiy17
Copy link

@gzemlevskiy17 gzemlevskiy17 commented Apr 22, 2025

PR Description

Implement a demo of the classical shadows algorithm.

I was unsure on how to use rebase or pre-commit.

Some notes

  • Please make sure that the notebook runs successfully with the latest Classiq version.

  • Please make sure that you placed the files in an appropriate folder

    • And that the file names are clear, descriptive, and match the notebook content.
      • Note that we require the file names of .ipynb and .qmod to be unique across this repository.
    • Plus, please make sure that all required files are included: .qmod, .synthesis_options.json, .metadata.json
    • And that images are embedded inside the notebook, not added as external files
  • If applicable, please include link to the paper on which the notebook is based, in the notebook itself.

  • Please use rebase on your branch (no merge commits)

  • Please link this PR to the relevant issue

  • Please make sure to run pre-commit when commiting changes

    • If you're using git in the terminal, make sure to install pre-commit via running pip install pre-commit followed by pre-commit install
    • Note that Classiq runs automatic code linting. Meaning that one of the tests verifies the output of pre-commit.
    • Also note that pre-commit may minorly alter some files. Make sure to git add the changes done by pre-commit

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@@ -0,0 +1,512 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Apr 24, 2025

Choose a reason for hiding this comment

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

Thank you @gzemlevskiy17 for this PR! Please provide details in Markdown about the code so we can review it properly.

  • Short introduction about what is implemented.
  • Explain major code blocks, and how they are related to parts of the implementation.
  • Add a snapshot of the quantum part from Classiq visualization.

Reply via ReviewNB

@@ -0,0 +1,512 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Apr 24, 2025

Choose a reason for hiding this comment

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

If you like, we have a function in our open-library that prepares a bell state. You can use it as well if you want.

https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_bell_state.ipynb


Reply via ReviewNB

@TomerGoldfriend
Copy link
Member

@gzemlevskiy17 are you still working on this?

@gzemlevskiy17
Copy link
Author

@TomerGoldfriend Yes, sorry I was working on developing the Classiq challenge for the FLIQ hackathon. I will update this PR soon.

@NadavClassiq
Copy link
Contributor

Hi @gzemlevskiy17 !
Still plan to complete this project?

@gzemlevskiy17
Copy link
Author

Hi @NadavClassiq. Yes! The project is finished, but I am still figuring out how to adhere to the contributing guidelines. I actually have a few questions:

I ran pre-commit and one test did not pass, specifically:

Auto add test............................................................Failed
- hook id: auto-add-tests
- exit code: 1

Executable `.internal/pre_commit_tools/auto_add_tests.py` is not executable

What should I do about this?

Also, since classical shadows involves applying random unitary gates, the circuit, and thus the quantum model, vary, so I don't know if I should generate a .qmod file as per the guidelines.

Finally, I am unsure of the git workflow I should follow, particularly where rebase comes in.

@NadavClassiq
Copy link
Contributor

Hi @gzemlevskiy17!

  1. Custom auto tests are not required in the community/paper_implementation_project/, which is where you should first contribute. We might later on move the notebook to a different location, and take care the testing issue.

  2. Regarding the qmods, if you can make it work in a reproducible way, using a random seed, that would be great :)
    Anyway, qmods are required, at least the final one. Whenever you are done, I will take a closer look and, worst case, will give a note.

  3. Regarding the GitHub workflow, you don't really need to rebase at the moment, as only you work on these files. Rebase is used to take your branch and add newer changes that were rebased and merged while you were still working.

Lmk if you need further help :)

@NadavClassiq NadavClassiq added the Paper Implementation Project Implement a paper using Classiq label Jun 30, 2025
@gzemlevskiy17
Copy link
Author

gzemlevskiy17 commented Jun 30, 2025

@NadavClassiq Thank you!

If I am contributing to community/, what would I write for the qmod_type and level tags in the metadata.json file? Also, the paper name is "Predicting Many Properties of a Quantum System from Very Few Measurements", which is very long. Should I use that name for the filenames or is it fine if I named all the files "classical_shadows..."

@NadavClassiq
Copy link
Contributor

Hi @gzemlevskiy17 !

You can use a shorter name, just write the full name with a proper link in the notebook.
Regarding the metadata.json, just keep it as it is from the algorithm you have copied it from.

Lmk if you need anything else :)

@gzemlevskiy17 gzemlevskiy17 reopened this Jul 12, 2025
@gzemlevskiy17
Copy link
Author

@NadavClassiq I've pushed my latest changes.

One part of my code uses a list of PauliTerms as a Hamiltonian, but since that has been deprecated as input for ExecutionSession.estimate(), it generates a warning. I decided to keep it, because another part of my code uses hamiltonian_to_matrix(), which needs a PauliTerm.

@NadavClassiq
Copy link
Contributor

Great Job @gzemlevskiy17 !

I'll be reviewing it soon, maybe with feedback and suggestions for improvement.

Thanks for the efforts!

@NadavClassiq NadavClassiq self-assigned this Aug 7, 2025
@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

What is \epsilon?


Reply via ReviewNB

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

The \ket did not render. Maybe there is a way to do \usepackage{braket} in markdown. Otherwise, use \rangle and \langle, which should be fine.

"tomographically complete ensemble": this is not defined. You do not need to provide a full and rigorous definition. Just mention that you will provide one example below.

"Select a random unitary transformation from a predefined, tomographically complete ensemble" -->

"Select a random unitary, $U$, transformation from a predefined, tomographically complete ensemble"


Reply via ReviewNB

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

Give reference to the figure (I think it is taken from the original paper).


Reply via ReviewNB

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

Maybe choose a different example than the one in pennylane? How about taking a state where you can also see some phase difference? for example \Phi^{-} where you will see a (-) sign.


Reply via ReviewNB

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

Remove.


Reply via ReviewNB

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

Line #7.            in_snapshots (list): List of snapshots. Will most likely be the global snapshots (list of ints in {0, 1}).

I do not understand the "Will most likely be..." comments here.


Reply via ReviewNB

Copy link
Author

Choose a reason for hiding this comment

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

If the user changes the implementation, then it might be different, but I will remove that phrase to avoid confusion.

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

I think you can find some numpy or scipy function for this, rather then writing it by yourself. It will be clearer, in my opinion.


Reply via ReviewNB

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

Work with the new SparsePauliOp instead of list[PauliTerm] . You can do observable = Pauli.Z(0)*Pauli.Z(1). This will work when calling es.estimate(). However, you will have to modify your estimate_observable .


Reply via ReviewNB

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

Line #1.    def error_bound(error, observables, failure_rate=0.01):

This function depends on the choice of the unitary ensemble, no?

If yes, please mention it.


Reply via ReviewNB

@@ -0,0 +1,893 @@
{
Copy link
Member

@TomerGoldfriend TomerGoldfriend Aug 24, 2025

Choose a reason for hiding this comment

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

Please remove this reference. It is OK that this notebook is inspired by that reference, however, please make sure that you do not copy text, and do not use the exact code and naming.


Reply via ReviewNB

@TomerGoldfriend
Copy link
Member

@gzemlevskiy17 any updates on this?

@gzemlevskiy17
Copy link
Author

@TomerGoldfriend Thank you for the suggestions! Sorry for the delay, I have had a busy start to the semester. I will be working on it this weekend.

@gzemlevskiy17
Copy link
Author

@TomerGoldfriend I replied to some of your comments on ReviewNB, could you please take a look?

@TomerGoldfriend
Copy link
Member

@TomerGoldfriend I replied to some of your comments on ReviewNB, could you please take a look?

Sure @gzemlevskiy17 , thanks for the update.

@gzemlevskiy17
Copy link
Author

@TomerGoldfriend Were you able to take a look at my questions? If not, please advise how to proceed, thanks!

@TomerGoldfriend
Copy link
Member

@TomerGoldfriend Were you able to take a look at my questions? If not, please advise how to proceed, thanks!

@gzemlevskiy17 not yet, I will review until the end of this week.

@TomerGoldfriend
Copy link
Member

@gzemlevskiy17 I think I answered all your questions, please let me know if otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Paper Implementation Project Implement a paper using Classiq
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants