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

Allow formatting in names of custom gates #3171

Closed
peendebak opened this issue Sep 30, 2019 · 0 comments · Fixed by #3224
Closed

Allow formatting in names of custom gates #3171

peendebak opened this issue Sep 30, 2019 · 0 comments · Fixed by #3224
Labels
status: pending PR It has one or more PRs pending to solve this issue

Comments

@peendebak
Copy link
Contributor

What is the expected enhancement?

Allow formatting of custom gate names in circuit diagrams. The names of custom gates are shown as plain text. It would be nice to format these as latex or html.
For example the following code generates a circuit diagram with a custom gate

from qiskit import QuantumCircuit
from qiskit.circuit import Gate

qc = QuantumCircuit(1, 1)
qc.append(Gate(name=r'X_t', num_qubits=1, params=[]), [0])
qc.measure([0, ], [0,])
qc.draw(output='latex', interactive=False, filename='test.png')

The custom gate is labelled as X_t, but I want the name to be formatted as an X with subscript t. The custom gate name is transformed by utf8tolatex, but it is escaping the _.
Also variations as qc.append(Gate(name=r'$X_t$', num_qubits=1, params=[]), [0]) do not work.

Note: here is also a discussion on stack exchange on this: https://quantumcomputing.stackexchange.com/questions/8329/how-to-plot-custom-gate-labels-in-qiskit

mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Sep 30, 2019
This commit adds a new flag latex_labels to the circuit_drawer for use
with the latex and latex_source drawer. When it is set to true it
disables the pylatexenc conversion from unicode input to a latex
encoding. This enables users who want to manual create gate names that
are properly latex encoded (for example to have gate names with
subscripts) to do so.

Fixes Qiskit#3171
@1ucian0 1ucian0 added the good first issue Good for newcomers label Oct 2, 2019
@mtreinish mtreinish added status: pending PR It has one or more PRs pending to solve this issue and removed good first issue Good for newcomers labels Oct 7, 2019
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Oct 8, 2019
This commit adds a new feature to the latex drawer that adds support for
a similar syntax to matplotlib's mathtext to labels on the latex drawer.
In matplotlib if you specify a string between two dollar signs (for
example $\gamma$) that string will be parsed with mpl's native TeX
expression parser and that will be used to layout and render the string
per the TeX syntax. This uses the same syntax as mathtext, and enables
users to write raw latex syntax as gate labels between a pair of dollar
signs. All characters outside of the dollar signs are treated as utf8
and get encoded by pylatexenc to create valid latex, however all text
inside the dollar signs get passed verbatim to the output latex. This
enables users to mix and match having their unicode encoded for them and
manually passing latex

Fixes Qiskit#3171
1ucian0 pushed a commit that referenced this issue Oct 28, 2019
* Add dual of mpl mathtext syntax for latex drawer labels

This commit adds a new feature to the latex drawer that adds support for
a similar syntax to matplotlib's mathtext to labels on the latex drawer.
In matplotlib if you specify a string between two dollar signs (for
example $\gamma$) that string will be parsed with mpl's native TeX
expression parser and that will be used to layout and render the string
per the TeX syntax. This uses the same syntax as mathtext, and enables
users to write raw latex syntax as gate labels between a pair of dollar
signs. All characters outside of the dollar signs are treated as utf8
and get encoded by pylatexenc to create valid latex, however all text
inside the dollar signs get passed verbatim to the output latex. This
enables users to mix and match having their unicode encoded for them and
manually passing latex

Fixes #3171

* Fix lint

* Use jupyter-execute instead of describing diagram

* Revert "Use jupyter-execute instead of describing diagram"

This reverts commit ab7bc18. Running
the code example in jupyter-execute will require a latex distribution
with qcircuit to be installed. That adds a lot of run time to the doc
build and a non-obvious dependency. To avoid this, we'll just rely on
the code example and a description of the output.
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this issue Aug 5, 2020
* Add dual of mpl mathtext syntax for latex drawer labels

This commit adds a new feature to the latex drawer that adds support for
a similar syntax to matplotlib's mathtext to labels on the latex drawer.
In matplotlib if you specify a string between two dollar signs (for
example $\gamma$) that string will be parsed with mpl's native TeX
expression parser and that will be used to layout and render the string
per the TeX syntax. This uses the same syntax as mathtext, and enables
users to write raw latex syntax as gate labels between a pair of dollar
signs. All characters outside of the dollar signs are treated as utf8
and get encoded by pylatexenc to create valid latex, however all text
inside the dollar signs get passed verbatim to the output latex. This
enables users to mix and match having their unicode encoded for them and
manually passing latex

Fixes Qiskit#3171

* Fix lint

* Use jupyter-execute instead of describing diagram

* Revert "Use jupyter-execute instead of describing diagram"

This reverts commit ab7bc18. Running
the code example in jupyter-execute will require a latex distribution
with qcircuit to be installed. That adds a lot of run time to the doc
build and a non-obvious dependency. To avoid this, we'll just rely on
the code example and a description of the output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending PR It has one or more PRs pending to solve this issue
Projects
None yet
3 participants