# mdrft/Blueqat

Python Framework for Universal Gate Model
Switch branches/tags
Nothing to show
Latest commit c167643 Oct 17, 2018
 Failed to load latest commit information. blueqat Oct 16, 2018 doc Sep 25, 2018 examples Oct 2, 2018 tests Sep 18, 2018 tutorial_en Oct 8, 2018 tutorial_ja Oct 16, 2018 .gitignore Oct 4, 2018 LICENSE Aug 29, 2018 MDR_Blueqat_color.png Oct 11, 2018 README.rst Oct 13, 2018 dev-requirements.txt Aug 5, 2018 optional-requirements.txt Oct 2, 2018 requirements.txt Aug 5, 2018 setup.py Oct 16, 2018

## blueqat

A quantum gate simulator

0.1.9

### Install

```git clone https://github.com/mdrft/blueqat
cd blueqat
pip3 install -e .
```

or

```pip3 install blueqat
```

### Circuit

```from blueqat import Circuit
import math

#number of qubit is not specified
c = Circuit()

#if you want to specified the number of qubit
c = Circuit(3) #3qubits
```

### Method Chain

```# write as chain
Circuit().h[0].x[0].z[0]

# write in separately
c = Circuit().h[0]
c.x[0].z[0]
```

### Slice

```Circuit().z[1:3] # Zgate on 1,2
Circuit().x[:3] # Xgate on (0, 1, 2)
Circuit().h[:] # Hgate on all qubits
Circuit().x[1, 2] # 1qubit gate with comma
```

### Rotation Gate

```Circuit().rz(math.pi / 4)[0]
```

### Measurement

```Circuit().m[0]
```

### Run()

```Circuit().h[0].cx[0,1].run()
```

### last_result() Method

```c = Circuit().h[0].cx[0,1].m[0]
c.run() # array([0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j])
c.last_result() # (1, 0)
```

### Hamiltonian

```from blueqat.pauli import *

hamiltonian1 = (1.23 * Z[0] + 4.56 * X[1] * Z[2]) ** 2
hamiltonian2 = (2.46 * Y[0] + 5.55 * Z[1] * X[2] * X[1]) ** 2
hamiltonian = hamiltonian1 + hamiltonian2
print(hamiltonian)
```

simplify the hamiltonian

```hamiltonian = hamiltonian.simplify() # 無駄な演算子を省き、シンプルにする
print(hamiltonian)
```

### VQE

```from blueqat import vqe
from blueqat.pauli import qubo_bit as q

hamiltonian = -3*q(0)-3*q(1)-3*q(2)-3*q(3)-3*q(4)+2*q(0)*q(1)+2*q(0)*q(2)+2*q(0)*q(3)+2*q(0)*q(4)+2*q(1)*q(2)+2*q(1)*q(3)+2*q(1)*q(4)+2*q(2)*q(3)+2*q(2)*q(4)+2*q(3)*q(4)
step = 2

result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, step)).run() # VQEこれだけ
print(result.most_common(12))
```

If you want to create an ising model hamiltonian use Z(x) instead of q(x) in the equation

```hamiltonian = Z(0)-3*Z(1)+2*Z(0)*Z(1)+2*Z(0)*Z(2)
```

### Blueqat to Qiskit

```qiskit.register(APItoken)
sampler = blueqat.vqe.get_qiskit_sampler(backend="backend name")
result = blueqat.vqe.Vqe(QaoaAnsatz(...), sampler=sampler).run(verbose=True)
```

### Blueqat to QASM

```Circuit.to_qasm()

#OPENQASM 2.0;
#include "qelib1.inc";
#qreg q[1];
#creg c[1];
#h q[0];
```

### Example

#### 2-qubit Grover

```from blueqat import Circuit
c = Circuit().h[:2].cz[0,1].h[:].x[:].cz[0,1].x[:].h[:].m[:]
c.run()
print(c.last_result()) # => (1, 1)
```

#### Maxcut QAOA

```from blueqat import vqe, pauli
edges = [(0, 1), (1, 2), (2, 3), (3, 0), (1, 3), (0, 2), (4, 0), (4, 3)]
ansatz = vqe.QaoaAnsatz(sum([pauli.Z(i) * pauli.Z(j) for i, j in edges]), 1)
result = vqe.Vqe(ansatz).run()
print(
"""   {4}
/ \\
{0}---{3}
| x |
{1}---{2}""".format(*result.most_common()[0][0]))
```

### Tutorial

https://github.com/mdrft/Blueqat/tree/master/tutorial_ja

### Author

Takumi Kato (MDR),Yuichiro Minato(MDR)