All Projects → cduck → bloch_sphere

cduck / bloch_sphere

Licence: MIT license
Visualization tools for the qubit Bloch sphere

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to bloch sphere

quantumjava
Samples related to "Quantum Computing for Java Developers"
Stars: ✭ 86 (+86.96%)
Mutual labels:  quantum-computing
Pulser
Library for pulse-level/analog control of neutral atom devices. Emulator with QuTiP.
Stars: ✭ 55 (+19.57%)
Mutual labels:  quantum-computing
learn-qc-with-python-and-qsharp
Companion code for Learn Quantum Computing with Python and Q# Book by Dr. Sarah Kaiser and Dr. Chris Granade 💖
Stars: ✭ 62 (+34.78%)
Mutual labels:  quantum-computing
Quantum-Computing-Resources
This repository contains the best resources for learning practical quantum computing. This repository will be updated frequently.
Stars: ✭ 60 (+30.43%)
Mutual labels:  quantum-computing
learning-quantum
Study resources for learning quantum computing
Stars: ✭ 51 (+10.87%)
Mutual labels:  quantum-computing
sike-java
SIKE for Java is a software library that implements experimental supersingular isogeny cryptographic schemes that aim to provide protection against attackers running a large-scale quantum computer.
Stars: ✭ 28 (-39.13%)
Mutual labels:  quantum-computing
Quantum-Machine-Learning
This repository contains implementations of Quantum Machine Learning algorithms, feature maps, variational circuits and research papers.
Stars: ✭ 47 (+2.17%)
Mutual labels:  quantum-computing
QuantumPoker
Quantum Poker – a serious pedagogical tool to learn quantum computing that is fun to play
Stars: ✭ 16 (-65.22%)
Mutual labels:  quantum-computing
Quantum-Computer-Simulator-with-Algorithms
C++ simulator of quantum registers and quantum algorithms
Stars: ✭ 15 (-67.39%)
Mutual labels:  quantum-computing
qsel
Quantum programming language putting entanglement and superposition front and center
Stars: ✭ 37 (-19.57%)
Mutual labels:  quantum-computing
BetaVQE.jl
Solving Quantum Statistical Mechanics with Variational Autoregressive Networks and Quantum Circuits
Stars: ✭ 27 (-41.3%)
Mutual labels:  quantum-computing
RustQIP
Quantum computing using rust. Efficient and a borrow-checked no cloning theorem!
Stars: ✭ 106 (+130.43%)
Mutual labels:  quantum-computing
ddsim
MQT DDSIM - A quantum circuit simulator based on decision diagrams written in C++
Stars: ✭ 45 (-2.17%)
Mutual labels:  quantum-computing
unitaryhack
Rules and information for the 2021 unitaryHACK event hosted by @unitaryfund
Stars: ✭ 16 (-65.22%)
Mutual labels:  quantum-computing
FastExpm.jl
Implementation of a fast exponential matrix for large matrices (full and sparse)
Stars: ✭ 22 (-52.17%)
Mutual labels:  quantum-computing
Quantum-Computing-Opportunities
Moved to Gitlab
Stars: ✭ 43 (-6.52%)
Mutual labels:  quantum-computing
liboqs-go
Go bindings for liboqs
Stars: ✭ 29 (-36.96%)
Mutual labels:  quantum-computing
dwave-hybrid
Hybrid Asynchronous Decomposition Sampler prototype framework.
Stars: ✭ 69 (+50%)
Mutual labels:  quantum-computing
vein
🔮⚡️Vein is an open source high-level strictly-typed programming language with a standalone OS, arm and quantum computing support.
Stars: ✭ 31 (-32.61%)
Mutual labels:  quantum-computing
YaoBlocks.jl
Standard basic quantum circuit simulator building blocks. (archived, for it is moved to Yao.jl)
Stars: ✭ 26 (-43.48%)
Mutual labels:  quantum-computing

Qubit Bloch Sphere Visualization

A collection of visualization tools for the qubit Bloch sphere. The Bloch sphere is a useful representation of the state of a single-qubit quantum computer.

X gate comparison with Hadamard-Z-Hadamard

See also: Feynman path integral visualization

Install

bloch_sphere is available on PyPI:

python3 -m pip install bloch_sphere

Prerequisites

Cairo needs to be installed separately to render videos. See platform-specific instructions for Linux, Windows, and macOS from Cairo. Below are some examples for installing Cairo on Linux distributions and macOS.

Ubuntu

sudo apt-get install libcairo2

macOS

Using homebrew:

brew install cairo

Usage

This package provides a command line tool to generate animations. In your shell, run the following (run animate_bloch -h for help).

animate_bloch hadamard x y s s
animate_bloch2 xy_vs_z x,y z

With annotations:

animate_bloch2 xy_vs_z_annotated \
    x,y z \
    --circuit '& \gate{X} & \gate{Y} & \qw & \push{=} & & \gate{Z} & \qw' \
    --equation '$YX\ket{\psi}=Z\ket{\psi}$' \
    --fps 20 \
    --mp4

Custom gates: custom;<x-axis>;<y-axis>;<z-axis>;<number half rotations>;<label>

animate_bloch2 custom_hzy "custom;0;1;1;1;Hzy" "s,h,inv_s"

Alternate drawing styles:

animate_bloch ry_gate_arrows --style arrows ry,0.666667 ry,0.666667 ry,0.666667

Ry(2π/3) gate

Code Examples

Visualize a single Bloch sphere

from bloch_sphere.animate_bloch import do_or_save_animation, AnimState

@do_or_save_animation('my_animation', save=False, fps=20, preview=True)
# Or
#@do_or_save_animation('my_animation', save='gif', fps=20, preview=True)
#@do_or_save_animation('my_animation', save='mp4', fps=20, preview=False)
def animate(state: AnimState):
    state.x_gate()
    state.y_gate()
    state.s_gate()
    state.s_gate()
    ...
    state.wait()  # Pause at the end

Example output animation

Compare two sequences of gates

from bloch_sphere.animate_bloch_compare import main

main('hzh_x', 'h,z,h'.split(','), 'x'.split(','),
     r'& \gate{H} & \gate{Z} & \gate{H} & \qw & \push{=} & & \gate{X} & \qw',
     r'$HZH\ket{\psi}=X\ket{\psi}$',
     mp4=False,
     fps=20,
     preview=True,
)

Or

import drawSvg as draw
import latextools
from bloch_sphere.animate_bloch_compare import render_animation

# Add some extra labels
zero_ket = draw.Group()
zero_ket.draw(latextools.render_snippet('$\ket{0}$', latextools.pkg.qcircuit),
              x=0, y=0, center=True, scale=0.015)
one_ket = draw.Group()
one_ket.draw(latextools.render_snippet('$\ket{1}$', latextools.pkg.qcircuit),
             x=0, y=0, center=True, scale=0.015)
zero_ket_inner = draw.Use(zero_ket, 0, 0, transform='scale(0.75)')
one_ket_inner = draw.Use(one_ket, 0, 0, transform='scale(0.75)')

w = 624*2  # Output width
fps = 20
draw_args = dict(
    w = w/2,
    outer_labels=[
        [(0, 0, 1), (-0.15, 0.13), zero_ket],
        [(0, 0, -1), (0.15, -0.13), one_ket],
    ],
    inner_labels=[
        [(0, 0, 0.8), (0, 0), zero_ket_inner],
        [(0, 0, -0.8), (0, 0), one_ket_inner],
    ],
)

gates1 = 'h,z,h'.split(',')
gates2 = 'x'.split(',')
def func1(state):
    state.draw_args = dict(draw_args)
    state.draw_args['inner_labels'] = []
    state.sphere_fade_in()
    state.apply_gate_list(gates1, final_wait=False)
    state.wait()
    for _ in gates2:
        state.i_gate()
    state.wait()
    state.wait()
    state.sphere_fade_out()
    state.wait()
def func2(state):
    state.draw_args = dict(draw_args)
    state.draw_args['inner_labels'] = []
    state.sphere_fade_in()
    for _ in gates1:
        state.i_gate()
    state.wait()
    state.apply_gate_list(gates2, final_wait=False)
    state.wait()
    state.wait()
    state.sphere_fade_out()
    state.wait()
render_animation('hzh_x_compare', func1, func2,
                 r'& \gate{H} & \gate{Z} & \gate{H} & \qw & \push{=} & & \gate{X} & \qw',
                 r'$HZH\ket{\psi}=X\ket{\psi}$',
                 save='gif',  # False, 'gif', or 'mp4'
                 fps=fps,
                 preview=True,
                 w=w)

Example output animation

Synthesize any gate as Rz, Rx, Rz

Any single-qubit gate can be decomposed into a series of three rotations about fixed axes, most commonly as rotations about Z, X, and Z. See the example code that generated the below animation.

Example output animation

Synthesize any gate as Rz, Rx(π/2), Rz, Rx(π/2), Rz

Any single-qubit gate can also be decomposed into a series of three Z rotations with fixed X rotations of π/2 (1/4 turn) in between. See the example code that generated the below animation.

Example output animation

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].