@yuichirominato 2019.02.09更新 89views

[debug]Checking unitary matrix of the circuit using blueqat


Introduction

When we developing a quantum application on python we usually want to check the unitary matrix of the circuit for the debug. We realize it on our blueqat.

Install and update

You can easily install it,

pip install blueqat

If you already using blueqat, please update

pip install -U blueqat

You need numpy, scipy, sympy (optional) for the function.

pip install numpy scipy sympy

Example

Let’s try some example importing sympy

from sympy import pi
from blueqat import Circuit

Circuit().rx(pi / 2)[0].cx[0, 1].run(backend="sympy_unitary")

⎡  √2    -√2⋅ⅈ                 ⎤
⎢  ──    ──────    0       0   ⎥
⎢  2       2                   ⎥
⎢                              ⎥
⎢-√2⋅ⅈ     √2                  ⎥
⎢──────    ──      0       0   ⎥
⎢  2       2                   ⎥
⎢                              ⎥
⎢                -√2⋅ⅈ     √2  ⎥
⎢  0       0     ──────    ──  ⎥
⎢                  2       2   ⎥
⎢                              ⎥
⎢                  √2    -√2⋅ⅈ ⎥
⎢  0       0       ──    ──────⎥
⎣                  2       2   ⎦

You can check your unitary matrix easily.

Jupyternotebook or Google colaboratory

On jupyternotebook you can export the unitary matrix on latex output.

Beautiful.

from sympy import *
from blueqat import Circuit
init_printing()

Circuit().rx(pi / 2)[0].cx[0, 1].run(backend="sympy_unitary")

If you are using GoogleColab, please add ! first.

!pip install blueqat

And make a setup to use mathjax on the browser.

from google.colab.output._publish import javascript
javascript(url="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default")

Then,

from sympy import *
from blueqat import Circuit
init_printing()

Circuit().rx(pi / 2)[0].cx[0, 1].run(backend="sympy_unitary")

It’s easy.

Example on QFT

Let’s see Quantum Fourier Transform on N=4

--H--Rz2--Rz3--Rz4--------------------------
-----*----|----|----H--Rz2--Rz3-------------
----------*----|-------*----|----H--Rz2-----
---------------*------------*-------*----H--
from sympy import *
from blueqat import Circuit
init_printing()

Circuit().x[:].h[0].rz(pi/4)[0].cx[1,0].rz(-pi/4)[0].cx[1,0].rz(pi/8)[0].cx[2,0].rz(-pi/8)[0].cx[2,0].rz(pi/16)[0].cx[3,0].rz(-pi/16)[0].cx[3,0].h[1].rz(pi/4)[1].cx[2,1].rz(-pi/4)[1].cx[2,1].rz(pi/8)[1].cx[3,1].rz(-pi/8)[1].cx[3,1].h[2].rz(pi/4)[2].cx[3,2].rz(-pi/4)[2].cx[3,2].h[3].run(backend="sympy_unitary")                                                                    

!!!!!

It’s efficient to use it for study on quantum circuit

Recommend


Back To Top