# Checking unitary matrix of the quantum circuit using Blueqat

May 19 · 2 min read

# 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

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 CircuitCircuit().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.

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")

!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

# What is Blueqat?

Blueqat is an open source library for quantum computer.

## How to install Blueqat?

Blueqat is provided as Python (ver 3.6+) library. You can install by pip.

pip install blueqat

The overlayed state has shifted so that 0 and 1 come to q2 in about half probability.

If you have any questions or suggestions, please feel free to contact us by our Slack community. (Join from here)

Written by