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

Add DumpOperation support in Q# #1885

Merged
merged 40 commits into from
Sep 30, 2024
Merged

Add DumpOperation support in Q# #1885

merged 40 commits into from
Sep 30, 2024

Conversation

billti
Copy link
Member

@billti billti commented Aug 25, 2024

This enables Q# code to call 'DumpOperation' which will output to console/debugger as text, or Jupyter notebooks as a LaTeX matrix.

e.g. from a notebook cell

%%qsharp

open Microsoft.Quantum.Diagnostics;
operation Foo(qs: Qubit[]) : Unit {
    H(qs[0]);
    CX(qs[0], qs[1]);
}

operation Main() : Unit {
    use qs = Qubit[2];
    Foo(qs);
    DumpMachine();
    Message("About to dump operation Foo");
    DumpOperation(2, Foo);
    ResetAll(qs);
}

Main()

Output is:

image

Copy link

github-actions bot commented Sep 4, 2024

Change in memory usage detected by benchmark.

Memory Report for 01c28ed

Test This Branch On Main Difference
compile core + standard lib 18047944 bytes 18002928 bytes 45016 bytes

DmitryVasilevsky and others added 6 commits September 19, 2024 00:46
* Updated general code so that 0 is recognized in Cartesian form. Also
propagated parameter to render 1 explicitly out of inner functions.
* Added function write_latex_for_complex_number for rendering a
standalone complex number. It differs from write_latex_for_term in
handling of special cases such as 0, 1, -1.
* Changed get_matrix_latex to call this new function. This reduced a
number of special cases, so I removed them from
get_latex_for_simple_term. Eventually all these special cases should go
away.
* Added tests for write_latex_for_complex_number. Also added test for
get_matrix_latex to check that rendering hasn't changed in the process.
* The following can still be improved in general case:
* i could be used directly in a fraction. Example: $\frac{1}{2}i$ could
be rendered as $\frac{i}{2}$.
* Brackets are not needed for standalone rendering. Example:
$-\left(1+i\right)$ could be rendered as $-1-i$
* No need to rationalize the denominator. Example: $\frac{\sqrt{2}}{2}$
could be rendered as $\frac{1}{\sqrt{2}}$

Co-authored-by: Dmitry Vasilevsky <[email protected]>
Copy link

Change in memory usage detected by benchmark.

Memory Report for e56359e

Test This Branch On Main Difference
compile core + standard lib 17927116 bytes 17882252 bytes 44864 bytes

Copy link

Change in memory usage detected by benchmark.

Memory Report for 0d67e36

Test This Branch On Main Difference
compile core + standard lib 17927116 bytes 17882252 bytes 44864 bytes

Copy link

Change in memory usage detected by benchmark.

Memory Report for 35d0967

Test This Branch On Main Difference
compile core + standard lib 17932132 bytes 17887268 bytes 44864 bytes

Copy link

Change in memory usage detected by benchmark.

Memory Report for dce2394

Test This Branch On Main Difference
compile core + standard lib 17932132 bytes 17887268 bytes 44864 bytes

Copy link

Change in memory usage detected by benchmark.

Memory Report for a6f8ae4

Test This Branch On Main Difference
compile core + standard lib 17932132 bytes 17887268 bytes 44864 bytes

Copy link
Collaborator

@swernli swernli left a comment

Choose a reason for hiding this comment

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

LGTM, though there is still the feedback from Mine to resolve.

@billti billti added this pull request to the merge queue Sep 30, 2024
Merged via the queue into main with commit c8c1338 Sep 30, 2024
18 checks passed
@billti billti deleted the billti/matrix branch September 30, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add DumpOperation to Q# library M.Q.Diagnostics
4 participants