We released blueqat ver. 0.4.7 and implemented Gray-code based multi-controlled gates.
Copy
# Update to latest version of blueqat
!pip install -U blueqat
Requirement already satisfied: blueqat in /opt/conda/lib/python3.9/site-packages (0.4.5)
Collecting blueqat
Downloading blueqat-0.4.7-py3-none-any.whl (66 kB)
[K |████████████████████████████████| 66 kB 444 kB/s eta 0:00:011
[?25hRequirement already satisfied: scipy>=1.5 in /opt/conda/lib/python3.9/site-packages (from blueqat) (1.6.3)
Requirement already satisfied: numpy>=1.19 in /opt/conda/lib/python3.9/site-packages (from blueqat) (1.19.5)
Installing collected packages: blueqat
Attempting uninstall: blueqat
Found existing installation: blueqat 0.4.5
Uninstalling blueqat-0.4.5:
Display all output >>>
Activate built-in macros
To activate macros, execute import blueqat.macros.
Copy
from blueqat import Circuit
import blueqat.macros
Now, built-in macros are available.
Draw the circuit
We add new macros for drawing the circuit. This feature requires qiskit.
Copy
Circuit().h[0].cx[0, 1].draw()
┌───┐
q_0: ┤ H ├──■──
└───┘┌─┴─┐
q_1: ─────┤ X ├
└───┘
c: 2/══════════
Copy
# In jupyter notebook, output='mpl' generates beautiful drawing.
# You may needs to run `pip install pylatexenc` before.
Circuit().h[0].cx[0, 1].draw(output='mpl')
<Figure size 206.852x204.68 with 1 Axes>
Multi-controlled gate
blueqat has ccx and ccz, but doesn't have multi-controlled gate. Therefore, we implemented them as macros.
Multi-controlled X, Z
c3x, c4x, c3z, c4z are available.
Circuit.c3x(c0, c1, c2, t): 3-controlled X Circuit.c3z(c0, c1, c2, t): 3-controlled Z Circuit.c4x(c0, c1, c2, c3, t): 4-controlled X Circuit.c4z(c0, c1, c2, c3, t): 4-controlled Z
Copy
for c0 in [0, 1]:
for c1 in [0, 1]:
for c2 in [0, 1]:
for c3 in [0, 1]:
c = Circuit()
if c0:
c.x[0]
if c1:
c.x[1]
if c2:
c.x[2]
if c3:
c.x[3]
c.c4x(0, 1, 2, 3, 4)
result = c.m[:].shots(10)
print(f'C4x |{c0}{c1}{c2}{c3}0>')
print(f'Expected: {c0}{c1}{c2}{c3}{c0*c1*c2*c3}, Actual:', result)
Multi-controlled rotation macros are also available.
R-gate and RZ-gate are same except global phase. However, controlled-R and controlled-RZ are different gate.
from math import pi
for c0 in [0, 1]:
for c1 in [0, 1]:
for c2 in [0, 1]:
c = Circuit()
if c0:
c.x[0]
if c1:
c.x[1]
if c2:
c.x[2]
c.mcry_gray(pi / 2, [0, 1, 2], 3)
if c0 * c1 * c2 == 0:
print(f"Expect: {c0}{c1}{c2}0: 100%")
else:
print(f"Expect: {c0}{c1}{c2}0: 50%, {c0}{c1}{c2}1: 50%")
print("Actual:", c.m[3].shots(100))