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

A circuit plotting routine using SymPy #62

Open
BoxiLi opened this issue Jun 19, 2021 · 2 comments
Open

A circuit plotting routine using SymPy #62

BoxiLi opened this issue Jun 19, 2021 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@BoxiLi
Copy link
Member

BoxiLi commented Jun 19, 2021

The current circuit plotting in qutip-qip uses LaTeX, which is powerful but requires dependencies that are hard to control as a Python package. The installation for users who do not already have a working tex environment is very clumsy.

As shown in this notebook. Sympy might have a way to do this already (see here). It is much easier to make SymPy an optional package than asking the user to install a full Tex distribution, which could be several Gigabytes large.
As Sympy uses a class for each gate, we could leave a method in our gate class that initialize this SymPy class, e.g:

class XGate(SingleQubitGate):
    ...
    def get_sympy_object(self):
        return sympy.physics.quantum.gate.X(self.targets[0])

And even better, SymPy seems to support QASM 2.0 gates! If that is true, we can first export our circuit to QASM then use SymPy to plot them. I haven't explored this yet.

@BoxiLi BoxiLi added the enhancement New feature or request label Aug 5, 2021
@TheCharmingSociopath
Copy link

Hi,

If this enhancement is still relevant (which I think it is, installing a Tex distribution is heavy and painful) can I take this issue up?

The approach you mentioned in the example seems easy to implement, push all the returned sympy gate objects into a list and write a function to plot them using sympy.physics.quantum.circuitplot, passing the said list as a parameter.

@BoxiLi
Copy link
Member Author

BoxiLi commented Apr 19, 2022

Hi @TheCharmingSociopath, yes, this enhancement is still relevant. You are very welcome to take this issue up.

The only thing is that right now our own gate classes have not yet been merged (#96). So you probably need to define get_sympy_object under the class Gate and add lots of if branches to check the name of the gate. Nonetheless, it should work, I think.

You probably also need to add another function that draws the sympy circuit. It would be nice to first have this in a separate file and then try to merge it with other workflows later when it is complete.

@BoxiLi BoxiLi added the help wanted Extra attention is needed label Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants