├── .gitignore ├── LICENSE.txt ├── README.md ├── bloch_sphere ├── __init__.py ├── animate_bloch.py └── animate_bloch_compare.py ├── examples ├── common_gates.md ├── hh_gate.gif ├── hzh_x_compare.gif ├── random_as_zxz.gif ├── random_as_zxzxz.gif ├── render_examples.py ├── ry_gate_arrows.gif ├── sqrt_xxxx_gate.gif ├── ststs_gate.gif ├── synthesize_from_rz_rx_rz.py ├── xx_gate.gif ├── xyss_gate.gif ├── xz_y_compare.gif ├── yy_gate.gif └── zz_gate.gif └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | /dist 2 | /*.egg-info 3 | /build 4 | 5 | # Mac files 6 | .DS_Store 7 | 8 | # cache files 9 | __pycache__/ 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2020 Casey Duckering 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Qubit Bloch Sphere Visualization 2 | 3 | A collection of visualization tools for the qubit Bloch sphere. 4 | The Bloch sphere is a useful representation of the state of a single-qubit quantum computer. 5 | 6 | ![X gate comparison with Hadamard-Z-Hadamard](https://raw.githubusercontent.com/cduck/bloch_sphere/master/examples/hzh_x_compare.gif) 7 | 8 | * [Animations for many common gates](https://github.com/cduck/bloch_sphere/blob/master/examples/common_gates.md) 9 | 10 | See also: [Feynman path integral visualization](https://github.com/cduck/feynman_path) 11 | 12 | # Install 13 | 14 | bloch\_sphere is available on PyPI: 15 | 16 | ```bash 17 | python3 -m pip install bloch_sphere 18 | ``` 19 | 20 | ## Prerequisites 21 | 22 | Cairo needs to be installed separately to render videos. 23 | See platform-specific [instructions for Linux, Windows, and macOS from Cairo](https://www.cairographics.org/download/). 24 | Below are some examples for installing Cairo on Linux distributions and macOS. 25 | 26 | **Ubuntu** 27 | 28 | ```bash 29 | sudo apt-get install libcairo2 30 | ``` 31 | 32 | **macOS** 33 | 34 | Using [homebrew](https://brew.sh/): 35 | 36 | ```bash 37 | brew install cairo 38 | ``` 39 | 40 | # Usage 41 | 42 | This package provides a command line tool to generate animations. 43 | In your shell, run the following (run `animate_bloch -h` for help). 44 | ```bash 45 | animate_bloch hadamard x y s s 46 | ``` 47 | 48 | ```bash 49 | animate_bloch2 xy_vs_z x,y z 50 | ``` 51 | 52 | With annotations: 53 | ```bash 54 | animate_bloch2 xy_vs_z_annotated \ 55 | x,y z \ 56 | --circuit '& \gate{X} & \gate{Y} & \qw & \push{=} & & \gate{Z} & \qw' \ 57 | --equation '$YX\ket{\psi}=Z\ket{\psi}$' \ 58 | --fps 20 \ 59 | --mp4 60 | ``` 61 | 62 | Custom gates: `custom;;;;;