blueqat
A Quantum Computing SDK
Version
Tutorial
https://github.com/Blueqat/Blueqat-tutorials
Notice
The back end has been changed to tensor network. The previous backend environment can still be used with .run(backend="numpy").
Install
git clone https://github.com/Blueqat/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(50) #50qubits
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]
Run
from blueqat import Circuit
Circuit(50).h[:].run()
Run(shots=n)
Circuit(100).x[:].run(shots=100)
# => Counter({'1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111': 100})
Single Amplitude
Circuit(4).h[:].run(amplitude="0101")
Expectation value of hamiltonian
from blueqat.pauli import Z
hamiltonian = 1*Z[0]+1*Z[1]
Circuit(4).x[:].run(hamiltonian=hamiltonian)
# => -2.0
Blueqat to QASM
Circuit().h[0].to_qasm()
#OPENQASM 2.0;
#include "qelib1.inc";
#qreg q[1];
#creg c[1];
#h q[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)
# => 7.5645*I + 5.6088*Z[0]*X[1]*Z[2] + 5.6088*X[1]*Z[2]*Z[0] + 20.793599999999998*X[1]*Z[2]*X[1]*Z[2] + 13.652999999999999*Y[0]*Z[1]*X[2]*X[1] + 13.652999999999999*Z[1]*X[2]*X[1]*Y[0] + 30.8025*Z[1]*X[2]*X[1]*Z[1]*X[2]*X[1]
Simplify the Hamiltonian
hamiltonian = hamiltonian.simplify()
print(hamiltonian)
#=>-2.4444000000000017*I + 27.305999999999997j*Y[0]*Y[1]*X[2] + 11.2176*Z[0]*X[1]*Z[2]
QUBO Hamiltonian
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)
print(hamiltonian)
# => -5.5*I + 1.0*Z[1] + 1.0*Z[2] + 1.0*Z[3] + 1.0*Z[4] + 0.5*Z[0]*Z[1] + 0.5*Z[0]*Z[2] + 0.5*Z[0]*Z[3] - 0.5*Z[0] + 0.5*Z[0]*Z[4]
Time Evolution
hamiltonian = [1.0*Z(0), 1.0*X[0]]
a = [term.get_time_evolution() for term in hamiltonian]
time_evolution = Circuit().h[0]
for evo in a:
evo(time_evolution, np.random.rand())
print(time_evolution)
# => Circuit(1).h[0].rz(-1.4543063361067243)[0].h[0].rz(-1.8400416676737137)[0].h[0]
QAOA
from blueqat import Circuit
from blueqat.utils import qaoa
from blueqat.pauli import qubo_bit as q
from blueqat.pauli import X,Y,Z,I
hamiltonian = q(0)-q(1)
step = 1
result = qaoa(hamiltonian, step)
result.circuit.run(shots=100)
# => Counter({'01': 99, '11': 1})
Circuit Drawing Backend
from blueqat import vqe
from blueqat.pauli import *
from blueqat.pauli import qubo_bit as q
#hamiltonian = q(0)-3*q(1)+2*q(0)*q(1)+3*q(2)*q(3)+q(4)*q(7)
hamiltonian = Z[0]-3*Z[1]+2*Z[0]*Z[1]+3*Z[2]*Z[3]+Z[4]
step = 8
result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, step)).run()
result.circuit.run(backend='draw')
Cloud System Connection (API Key is required)
from bqcloud import register_api
api = register_api("Your API Key")
from bqcloud import load_api
api = load_api()
from blueqat import Circuit
from bqcloud import Device
task = api.execute(Circuit().h[0].cx[0, 1], Device.IonQDevice, 10)
#task = api.execute(Circuit().h[0].cx[0, 1], Device.AspenM1, 10)
# Wait 10 sec. If complete, result is returned, otherwise, None is returned.
result = task.wait(timeout=10)
if result:
print(result.shots())
else:
print("timeout")
Document
https://blueqat.readthedocs.io/en/latest/
Contributors
Disclaimer
Copyright 2022 The Blueqat Developers.
Metadata
Release files for blueqat 2.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| blueqat-2.0.4.tar.gz | 54.9 kB | Without provenance | Details for blueqat-2.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| blueqat-2.0.4-py3-none-any.whl | Python 3 | none | any | Details for blueqat-2.0.4-py3-none-any.whl |
Total release size: 123.8 kB
Release files / blueqat-2.0.4.tar.gz
| Download URL | blueqat-2.0.4.tar.gz |
|---|---|
| Size | 54.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fca9bd17716566487452749ac0cb06cf4eb43fffdb33fc87231481371860ba55
|
|
BLAKE2b-256 checksum How to use checksums |
b4d958aebf50fc2f1f52363680ee70936c677789963fa329b4768a0c7f911a96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Release files / blueqat-2.0.4-py3-none-any.whl
| Download URL | blueqat-2.0.4-py3-none-any.whl |
|---|---|
| Size | 68.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82017bff22364f57e17e7e834749f7540bebb9a290aad2b7e007d4993826c625
|
|
BLAKE2b-256 checksum How to use checksums |
e015cb1b329d2ab2e1d3428f9e7a1dea8bfa8248108e6d9923835dca6d441d9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Security for blueqat 2.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.