Skip to content

Support common notations in circuit_to_latex_using_qcircuit #4685

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

Open
fedimser opened this issue Nov 14, 2021 · 15 comments
Open

Support common notations in circuit_to_latex_using_qcircuit #4685

fedimser opened this issue Nov 14, 2021 · 15 comments
Assignees
Labels
area/latex area/qcircuit good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/feature-request Describes new functionality no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@fedimser
Copy link
Contributor

fedimser commented Nov 14, 2021

Is your feature request related to a use case or problem? Please describe.
There are common notations for some gates supported by QCircuit, but Cirq's circuit_to_latex_using_qcircuit doesn't use them. This includes:

  • SWAP gate which rendered as rectangle with "SWAP" inside it, instead of two crosses connected by a line.
  • Multi-controlled X gate, where some controls are "1" and some are "0". Conventional notation for "0" controls is unfilled circle.

Describe the solution you'd like
Add special handling for common conventional notations (supported by QCircuit) to circuit_to_latex_using_qcircuit.

[optional] Describe alternatives/workarounds you've considered
I wrote a find-and-replace post-processing script which produces desired result in my case:

def process_latex(s):
    s = s.replace('\\multigate{1}{\\text{SWAP}}', '\\qswap')
    s = s.replace('\\ghost{\\text{SWAP}}', '\\qswap\\qwx')
    s = s.replace('\\gate{\\text{@}}','\\control')
    s = s.replace('\\gate{\\text{(0)}}','\\ctrlo{}')
    s = s.replace('\\gate{\\text{X}}','\\targ')
    while '   ' in s:
        s = s.replace('   ', ' ')
    return s

[optional] Additional context (e.g. screenshots)
Example of circuit, its current rendering and desired rendering (which was obtained with a script above):

Screenshot from 2021-11-14 09-30-23

What is the urgency from your perspective for this issue? Is it blocking important work?
P3

@fedimser fedimser added the kind/feature-request Describes new functionality label Nov 14, 2021
@viathor viathor added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Nov 17, 2021
@tanujkhattar tanujkhattar added no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Nov 17, 2021
@jay-tau
Copy link

jay-tau commented Jul 19, 2022

I would like to attempt working on this, please.

@jay-tau
Copy link

jay-tau commented Jul 23, 2022

Hi @tanujkhattar @fedimser,

I am still very very keen to work on this issue.
Would it be possible to assign it to me?

Cheers,
Joel

@vtomole
Copy link
Collaborator

vtomole commented Jul 23, 2022

@jay-tau I've assigned it to you.

@jay-tau
Copy link

jay-tau commented Aug 17, 2022

Hello,
Unfortunately, I am unable to solve the issue. Thank you for giving me a chance to work on this issue.
Hopefully, this can be solved by someone else.

@NikolaiLong
Copy link

Hello @vtomole, @pavoljuhas, @fedimser I would like to work on this issue. Could someone please assign it to me.

Initial Completion Estimate ETA: 2/28/25

@NikolaiLong
Copy link

I was assigned this issue yesterday; therefore, I am pushing back my eta.

Completion Estimate ETA: 3/7/25

@NikolaiLong
Copy link

@fedimser is there a particular name for the diagram that contains all of the gates you've listed to be reformatted? For naming the testcase.

@NikolaiLong
Copy link

Successfully recreated desired circuit in testcase, does this look accurate @fedimser?

Image

Will now begin work on circuit_to_latex_using_qcircuit method.

Spacing discrepancies addressed with the postprocessing function will most likely not be an issue after large swap boxes are not in use anymore.

@fedimser
Copy link
Contributor Author

fedimser commented Mar 4, 2025

@NikolaiLong, the circuit is just an example, it has no particlar name.

@NikolaiLong
Copy link

NikolaiLong commented Mar 4, 2025

Debugging of failing testcase complete -

  • Modifications required to convert_text_diagram_info_to_qcircuit_diagram_info() for the \targ \control \ctrlo{} issues.
  • Modifications required to multigate_qcircuit_diagram_info() to fix the multigate/swap/ ghost/swap issues.

ETA: On Track for 3/7/2025

@NikolaiLong
Copy link

I've been much busier with work this week than anticipated, pushing eta back:

Updated Completion ETA: 3/14/2025

@NikolaiLong
Copy link

All text conversions have been resolved
Image

Will finish pdf validation tomorrow and hopefully submit a PR before Cirq-Sync on Wednesday.

@NikolaiLong
Copy link

PDF generation is accurate - testcase still needs additional validations added before this task is complete.

Image

@NikolaiLong
Copy link

NikolaiLong commented Mar 18, 2025

All tests passing locally, pdf test is out of scope for this issue and has been left commented out.
New PR Raised: #7151

@NikolaiLong
Copy link

I apologize for the in-activity on this issue. I have had to study for the past month and will need continue for potentially a couple months. I will try to work in some time to continue development of this solution in my free time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/latex area/qcircuit good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/feature-request Describes new functionality no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
Status: No status
Development

No branches or pull requests

9 participants