qpic


Nameqpic JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/qpic/qpic
SummaryCreating quantum circuit diagrams in TikZ
upload_time2023-11-13 23:29:01
maintainer
docs_urlNone
authorSandy Kutin, Thomas Draper
requires_python
licenseGPL
keywords qpic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ####################################
⟨q\|pic⟩: Quantum circuits made easy
####################################

.. image:: docs/images/qpic.png

**************************************************************
A compiler from quantum circuits to graphical representations.
**************************************************************

.. image:: https://img.shields.io/pypi/v/qpic.svg
        :target: https://pypi.python.org/pypi/qpic

.. TODO: Publish badge after porting to ReadTheDocs
    .. image:: https://readthedocs.org/projects/qpic/badge/?version=latest
            :target: https://readthedocs.org/projects/qpic/?badge=latest
            :alt: Documentation Status

-  Free software: GNU GPLv3 license
-  Documentation: `⟨q\|pic⟩ manual <doc/qpic_doc.pdf>`_

Features
========

The ⟨q\|pic⟩ language provides a concise, readable, ASCII format for
describing quantum circuits. ``qpic`` converts ⟨q\|pic⟩ files to the
scientific paper standard of LaTeX using TikZ graphic commands.

-  Automatic placement of circuit components.
-  Human readable.
-  Input ⟨q\|pic⟩ syntax can be produced by other scripts.
-  Can be included in LaTeX documents in TikZ or PDF form.

⟨q\|pic⟩ produces high quality graphics quickly. The following graphic
illustrating part of a ripple carry adder 

.. image:: docs/images/Adder_CDKM_MAJ.png

is compiled from the ⟨q\|pic⟩ code

::

    a W a a\oplus{c}
    b W b b\oplus{c}
    c W c \mbox{MAJ}(a,b,c)

    a b c G \rotatebox{90}{MAJ}
    =
    +b c
    +a c
    a b +c

Examples
========

Basic quantum teleportation circuit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. image:: docs/images/BasicTeleportation.png

This classic diagram derives from the following code:

::

    a W |\psi\rangle
    b c W |\beta_{00}\rangle<
    c W |\psi\rangle
    a +b
    a H
    a b M
    c X b:owire
    c Z a:owire

Decorated quantum teleportation circuit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

⟨q\|pic⟩ has additional features for commenting or highlighting parts of
a circuit.

.. image:: docs/images/QuantumTeleportation.png

This diagram derives from the following:

::

    PREAMBLE \providecommand{\K}[1]{\left|#1\right\rangle} # Define ket command
    a  W \K{\phi} [x]
    x1 W type=o # Empty wire used for positioning
    x0 W style=dashed # Dividing line
    x2 W type=o # Empty wire used for positioning
    b0 W \K{0} [y]
    b1 W \K{0} \K{\phi}

    VERTICAL 0
    b1 H    % $\K{\phi}\K{0}(\K{0}{+}\K{1})$
    +b0 b1  % $(\alpha\K{0}{+}\beta\K{1})(\K{00}{+}\K{11})$
    b0 x1 PERMUTE
    +b0 a   %$\scriptstyle\alpha\K{0}(\K{00}{+}\K{11}){+}\beta\K{1}(\K{10}{+}\K{01})$
    a H     % $\sum_{x,y}\K{xy}(\alpha\K{y}{+}(-1)^x\beta\K{\bar{y}})$
    a b0 M  % $[xy](\alpha\K{y}{+}(-1)^x\beta\K{\bar{y}})$
    x1 x2 a b0 PERMUTE
    +b1 b0  % $[xy](\alpha\K{0}{+}(-1)^x\beta\K{1})$
    b1 a    % $[xy](\alpha\K{0}{+}\beta\K{1})$

    # Colored boxes
    b0 b1 x1 x2 @ 0 2 fill=green style=rounded_corners %% $[qq]$ Quantum entanglement
    a b0 x2 x1 @ 6 6 fill=blue style=rounded_corners %% \hspace{.5cm}$2[c\rightarrow c]$ Classical channel

For an explanation of ``qpic`` commands and more examples, see the
`official documentation <doc/qpic_doc.pdf>`_.

Installation
~~~~~~~~~~~~

Recommended installation method is
`pip <https://en.wikipedia.org/wiki/Pip_(package_manager)>`_. Current
versions of Python 2 and 3 include pip. For older versions, use `pip
installation instructions <https://pip.pypa.io/en/stable/installing/>`_.

``pip install qpic``

If you do not have permission to install or wish to install ``qpic`` as
a single user, add ``$HOME/.local/bin`` to your ``$PATH`` and install
using

``pip install --user qpic``

Uninstall
~~~~~~~~~

To uninstall ``qpic`` simply type

``pip uninstall qpic``

Stand alone script
~~~~~~~~~~~~~~~~~~

To try out the basic script without installation:

1. Download the file ``qpic.py``. (located in the ``qpic`` directory)
2. Run ``python qpic.py your_file.qpic > your_file.tex``.

Running ⟨q\|pic⟩
~~~~~~~~~~~~~~~~

``qpic`` generates TikZ code by default. ``qpic`` can also generate pdf
files using ``pdflatex`` and png files using ``convert`` (from
ImageMagic).

Create TikZ file ``diagram.tikz``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``qpic -f tikz diagram.qpic``

Create PDF file ``diagram.pdf``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``qpic -f pdf diagram.qpic``

Create PNG file ``diagram.png``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``qpic -f png diagram.qpic``

Using ⟨q\|pic⟩ with LaTeX
=========================

Including graphics in LaTeX documents
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

There are two main methods for including ⟨q\|pic⟩ in LaTeX documents.
Each has its advantage in certain areas. They are:

-  Include TikZ code directly
-  Include as a PDF graphic

TikZ
~~~~

``qpic my_graphic.qpic`` produces a TikZ file named ``my_graphic.tikz``,
which can be directly included into a normal LaTeX document. You will
need to add

::

    \usepackage{tikz}
    \usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing}

to the preamble of your paper. Graphics can then be included with the
command:

::

    \input{filename.tikz}

In some cases, additional TeX commands may be required in the preamble.
(These will be in the ``.tikz`` file preceded by ``%!``.) See the full
⟨q\|pic⟩ documentation for when additional packages are required.

PDF
~~~

``qpic -f pdf my_graphic.qpic`` will produce a PDF file named
``my_graphic.pdf``. This graphic can be viewed directly with a PDF
viewer. To insert the graphic into a LaTeX document, add the following
line to the preamble:

::

    \usepackage{graphicx}

and include the file using the command:

::

    \includegraphics{my_graphic.pdf}

This method requires the document to be processed with pdfLaTeX. For
further information see the full `⟨q\|pic⟩ documentation <doc/qpic_doc.pdf>`_.


=======
History
=======

1.1.0 (2023-11-13)
------------------

* Update for Python 3.11+

1.0.3 (2022-11-16)
------------------

* Handle deprecation of collections.Mapping in Python 3.10+

1.0.2 (2016-04-20)
------------------

* Fix Python3 unicode bug.

1.0.1 (2016-03-18)
------------------

* Convert README to ReStructuredText for PyPi.

1.0.0 (2016-03-09)
------------------

* First release on PyPI.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/qpic/qpic",
    "name": "qpic",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "qpic",
    "author": "Sandy Kutin, Thomas Draper",
    "author_email": "kutin@idaccr.org, tdraper@ccr-lajolla.org",
    "download_url": "",
    "platform": null,
    "description": "####################################\n\u27e8q\\|pic\u27e9: Quantum circuits made easy\n####################################\n\n.. image:: docs/images/qpic.png\n\n**************************************************************\nA compiler from quantum circuits to graphical representations.\n**************************************************************\n\n.. image:: https://img.shields.io/pypi/v/qpic.svg\n        :target: https://pypi.python.org/pypi/qpic\n\n.. TODO: Publish badge after porting to ReadTheDocs\n    .. image:: https://readthedocs.org/projects/qpic/badge/?version=latest\n            :target: https://readthedocs.org/projects/qpic/?badge=latest\n            :alt: Documentation Status\n\n-  Free software: GNU GPLv3 license\n-  Documentation: `\u27e8q\\|pic\u27e9 manual <doc/qpic_doc.pdf>`_\n\nFeatures\n========\n\nThe \u27e8q\\|pic\u27e9 language provides a concise, readable, ASCII format for\ndescribing quantum circuits. ``qpic`` converts \u27e8q\\|pic\u27e9 files to the\nscientific paper standard of LaTeX using TikZ graphic commands.\n\n-  Automatic placement of circuit components.\n-  Human readable.\n-  Input \u27e8q\\|pic\u27e9 syntax can be produced by other scripts.\n-  Can be included in LaTeX documents in TikZ or PDF form.\n\n\u27e8q\\|pic\u27e9 produces high quality graphics quickly. The following graphic\nillustrating part of a ripple carry adder \n\n.. image:: docs/images/Adder_CDKM_MAJ.png\n\nis compiled from the \u27e8q\\|pic\u27e9 code\n\n::\n\n    a W a a\\oplus{c}\n    b W b b\\oplus{c}\n    c W c \\mbox{MAJ}(a,b,c)\n\n    a b c G \\rotatebox{90}{MAJ}\n    =\n    +b c\n    +a c\n    a b +c\n\nExamples\n========\n\nBasic quantum teleportation circuit\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. image:: docs/images/BasicTeleportation.png\n\nThis classic diagram derives from the following code:\n\n::\n\n    a W |\\psi\\rangle\n    b c W |\\beta_{00}\\rangle<\n    c W |\\psi\\rangle\n    a +b\n    a H\n    a b M\n    c X b:owire\n    c Z a:owire\n\nDecorated quantum teleportation circuit\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\u27e8q\\|pic\u27e9 has additional features for commenting or highlighting parts of\na circuit.\n\n.. image:: docs/images/QuantumTeleportation.png\n\nThis diagram derives from the following:\n\n::\n\n    PREAMBLE \\providecommand{\\K}[1]{\\left|#1\\right\\rangle} # Define ket command\n    a  W \\K{\\phi} [x]\n    x1 W type=o # Empty wire used for positioning\n    x0 W style=dashed # Dividing line\n    x2 W type=o # Empty wire used for positioning\n    b0 W \\K{0} [y]\n    b1 W \\K{0} \\K{\\phi}\n\n    VERTICAL 0\n    b1 H    % $\\K{\\phi}\\K{0}(\\K{0}{+}\\K{1})$\n    +b0 b1  % $(\\alpha\\K{0}{+}\\beta\\K{1})(\\K{00}{+}\\K{11})$\n    b0 x1 PERMUTE\n    +b0 a   %$\\scriptstyle\\alpha\\K{0}(\\K{00}{+}\\K{11}){+}\\beta\\K{1}(\\K{10}{+}\\K{01})$\n    a H     % $\\sum_{x,y}\\K{xy}(\\alpha\\K{y}{+}(-1)^x\\beta\\K{\\bar{y}})$\n    a b0 M  % $[xy](\\alpha\\K{y}{+}(-1)^x\\beta\\K{\\bar{y}})$\n    x1 x2 a b0 PERMUTE\n    +b1 b0  % $[xy](\\alpha\\K{0}{+}(-1)^x\\beta\\K{1})$\n    b1 a    % $[xy](\\alpha\\K{0}{+}\\beta\\K{1})$\n\n    # Colored boxes\n    b0 b1 x1 x2 @ 0 2 fill=green style=rounded_corners %% $[qq]$ Quantum entanglement\n    a b0 x2 x1 @ 6 6 fill=blue style=rounded_corners %% \\hspace{.5cm}$2[c\\rightarrow c]$ Classical channel\n\nFor an explanation of ``qpic`` commands and more examples, see the\n`official documentation <doc/qpic_doc.pdf>`_.\n\nInstallation\n~~~~~~~~~~~~\n\nRecommended installation method is\n`pip <https://en.wikipedia.org/wiki/Pip_(package_manager)>`_. Current\nversions of Python 2 and 3 include pip. For older versions, use `pip\ninstallation instructions <https://pip.pypa.io/en/stable/installing/>`_.\n\n``pip install qpic``\n\nIf you do not have permission to install or wish to install ``qpic`` as\na single user, add ``$HOME/.local/bin`` to your ``$PATH`` and install\nusing\n\n``pip install --user qpic``\n\nUninstall\n~~~~~~~~~\n\nTo uninstall ``qpic`` simply type\n\n``pip uninstall qpic``\n\nStand alone script\n~~~~~~~~~~~~~~~~~~\n\nTo try out the basic script without installation:\n\n1. Download the file ``qpic.py``. (located in the ``qpic`` directory)\n2. Run ``python qpic.py your_file.qpic > your_file.tex``.\n\nRunning \u27e8q\\|pic\u27e9\n~~~~~~~~~~~~~~~~\n\n``qpic`` generates TikZ code by default. ``qpic`` can also generate pdf\nfiles using ``pdflatex`` and png files using ``convert`` (from\nImageMagic).\n\nCreate TikZ file ``diagram.tikz``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``qpic -f tikz diagram.qpic``\n\nCreate PDF file ``diagram.pdf``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``qpic -f pdf diagram.qpic``\n\nCreate PNG file ``diagram.png``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``qpic -f png diagram.qpic``\n\nUsing \u27e8q\\|pic\u27e9 with LaTeX\n=========================\n\nIncluding graphics in LaTeX documents\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThere are two main methods for including \u27e8q\\|pic\u27e9 in LaTeX documents.\nEach has its advantage in certain areas. They are:\n\n-  Include TikZ code directly\n-  Include as a PDF graphic\n\nTikZ\n~~~~\n\n``qpic my_graphic.qpic`` produces a TikZ file named ``my_graphic.tikz``,\nwhich can be directly included into a normal LaTeX document. You will\nneed to add\n\n::\n\n    \\usepackage{tikz}\n    \\usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing}\n\nto the preamble of your paper. Graphics can then be included with the\ncommand:\n\n::\n\n    \\input{filename.tikz}\n\nIn some cases, additional TeX commands may be required in the preamble.\n(These will be in the ``.tikz`` file preceded by ``%!``.) See the full\n\u27e8q\\|pic\u27e9 documentation for when additional packages are required.\n\nPDF\n~~~\n\n``qpic -f pdf my_graphic.qpic`` will produce a PDF file named\n``my_graphic.pdf``. This graphic can be viewed directly with a PDF\nviewer. To insert the graphic into a LaTeX document, add the following\nline to the preamble:\n\n::\n\n    \\usepackage{graphicx}\n\nand include the file using the command:\n\n::\n\n    \\includegraphics{my_graphic.pdf}\n\nThis method requires the document to be processed with pdfLaTeX. For\nfurther information see the full `\u27e8q\\|pic\u27e9 documentation <doc/qpic_doc.pdf>`_.\n\n\n=======\nHistory\n=======\n\n1.1.0 (2023-11-13)\n------------------\n\n* Update for Python 3.11+\n\n1.0.3 (2022-11-16)\n------------------\n\n* Handle deprecation of collections.Mapping in Python 3.10+\n\n1.0.2 (2016-04-20)\n------------------\n\n* Fix Python3 unicode bug.\n\n1.0.1 (2016-03-18)\n------------------\n\n* Convert README to ReStructuredText for PyPi.\n\n1.0.0 (2016-03-09)\n------------------\n\n* First release on PyPI.\n",
    "bugtrack_url": null,
    "license": "GPL",
    "summary": "Creating quantum circuit diagrams in TikZ",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/qpic/qpic"
    },
    "split_keywords": [
        "qpic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "58ba62fdd19503f04a9663d8124633a98820b8ac6bc52a08dc1f9ae4325f0d8e",
                "md5": "d97086137f08a3f7827aa50d41aa5d18",
                "sha256": "1b4006bf0ea65814f13e56bc6078c1d188c83d2e9dc13388275b1eab896750e0"
            },
            "downloads": -1,
            "filename": "qpic-1.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d97086137f08a3f7827aa50d41aa5d18",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 76309,
            "upload_time": "2023-11-13T23:29:01",
            "upload_time_iso_8601": "2023-11-13T23:29:01.163462Z",
            "url": "https://files.pythonhosted.org/packages/58/ba/62fdd19503f04a9663d8124633a98820b8ac6bc52a08dc1f9ae4325f0d8e/qpic-1.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-13 23:29:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "qpic",
    "github_project": "qpic",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "qpic"
}
        
Elapsed time: 0.52720s