Skip to content

Commit

Permalink
update 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
minatoyuichiro committed May 22, 2022
1 parent 5bb36c5 commit e762f8a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 101 deletions.
115 changes: 23 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,7 @@ A Quantum Computing SDK
https://github.com/Blueqat/Blueqat-tutorials

### Notice
The backend of blueqat will be changed to tensor network in the near future. Now try specifying the back end as "quimb".

install required

```
pip install --no-deps -U git+https://github.com/jcmgray/quimb.git@develop autoray
```

```python
from blueqat import Circuit
Circuit(50).h[:].run(backend="quimb")
```

Get the single amplitude
```python
Circuit(4).h[:].run(backend="quimb", amplitude="0101")
```

Get the sample
```python
Circuit(4).h[:].run(backend="quimb", shots=100)
```

Get the expectation value of hamiltonian
```python
from blueqat.pauli import Z
hamiltonian = 1*Z[0]+1*Z[1]
Circuit(4).x[:].run(backend="quimb", hamiltonian=hamiltonian)
```
The back end has been changed to tensor network. The previous backend environment can still be used with .run(backend="numpy").

### Install
```
Expand All @@ -62,7 +34,7 @@ import math
c = Circuit()

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

### Method Chain
Expand All @@ -88,28 +60,29 @@ Circuit().x[1, 2] # 1qubit gate with comma
Circuit().rz(math.pi / 4)[0]
```

### Measurement
### Run
```python
Circuit().m[0]
from blueqat import Circuit
Circuit(50).h[:].run()
```

### Run() to get state vector
### Run(shots=n)
```python
Circuit().h[0].cx[0,1].run()
# => array([0.70710678+0.j, 0.+0.j, 0.+0.j, 0.70710678+0.j])
Circuit(100).x[:].run(shots=100)
# => Counter({'1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111': 100})
```

### Run(shots=n)
### Single Amplitude
```python
c = Circuit().h[0].cx[0,1].m[:]
c.run(shots=100)
# => Counter({'00': 48, '11': 52})
Circuit(4).h[:].run(amplitude="0101")
```

### State Vector Initialization
### Expectation value of hamiltonian
```python
Circuit(2).m[:].run(shots=100, initial=np.array([0, 1, 1, 0])/np.sqrt(2))
# => Counter({'10': 51, '01': 49})
from blueqat.pauli import Z
hamiltonian = 1*Z[0]+1*Z[1]
Circuit(4).x[:].run(hamiltonian=hamiltonian)
# => -2.0
```

### Blueqat to QASM
Expand Down Expand Up @@ -153,30 +126,6 @@ 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]
```

### VQE
```python
from blueqat import Circuit
from blueqat.pauli import X, Y, Z, I
from blueqat.vqe import AnsatzBase, Vqe

class OneQubitAnsatz(AnsatzBase):
def __init__(self, hamiltonian):
super().__init__(hamiltonian.to_expr(), 2)
self.step = 1

def get_circuit(self, params):
a, b = params
return Circuit().rx(a)[0].rz(b)[0]

# hamiltonian
h = 1.23 * I - 4.56 * X(0) + 2.45 * Y(0) + 2.34 * Z(0)

result = Vqe(OneQubitAnsatz(h)).run()
print(runner.ansatz.get_energy_sparse(result.circuit))

# => -4.450804074762511
```

### Time Evolution
```python
hamiltonian = [1.0*Z(0), 1.0*X[0]]
Expand All @@ -193,38 +142,20 @@ print(time_evolution)

### QAOA
```python
from blueqat import vqe
from blueqat.pauli import *
from blueqat import Circuit
from Blueqat.blueqat.utils import qaoa
from blueqat.pauli import qubo_bit as q

hamiltonian = q(0)-3*q(1)+2*q(0)*q(1)
#hamiltonian = -0.5*I - Z[0] + 1.0*Z[1] + 0.5*Z[0]*Z[1]
step = 2
from blueqat.pauli import X,Y,Z,I

result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, step)).run()
print(result.most_common(4))

# => (((0, 1), 0.9874053861648978), ((1, 0), 0.00967786055983366), ((0, 0), 0.0014583766376339746), ((1, 1), 0.0014583766376339703))
```

### QAOA Mixer
```python
hamiltonian = q(0)-3*q(1)+2*q(0)*q(1)
step = 2
init = Circuit().h[0].cx[0,1].x[1]
mixer = (X[0]*X[1] + Y[0]*Y[1])*0.5
hamiltonian = q(0)-q(1)
step = 1

result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, step, init, mixer)).run()
print(result.most_common(4))
result = qaoa(hamiltonian, step)
result.circuit.run(shots=100)

# => (((0, 1), 0.9999886003516928), ((1, 0), 1.1399648305716677e-05), ((0, 0), 1.5176327961771419e-31), ((1, 1), 4.006785342235446e-32))
# => Counter({'01': 99, '11': 1})
```

### Select Scipy Minimizer
```python
minimizer = vqe.get_scipy_minimizer(method="COBYLA")
result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, step), minimizer=minimizer).run()
```

### Circuit Drawing Backend
```python
Expand Down
3 changes: 1 addition & 2 deletions blueqat/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@

"""The version of blueqat."""

__version__ = "1.0.4"
#__version__ = "0.5.0-dev"
__version__ = "2.0.0"
2 changes: 1 addition & 1 deletion blueqat/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"draw": DrawCircuit,
"quimb": Quimb,
}
DEFAULT_BACKEND_NAME = "numpy"
DEFAULT_BACKEND_NAME = "quimb"
6 changes: 1 addition & 5 deletions optional-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
qiskit>=0.15.0
sympy>=1.8
numba>=0.53.1
networkx>=2.6.3
matplotlib>=3.5.1
autoray>=0.2.5
quimb @ git+https://github.com/jcmgray/quimb.git@c34bb13ccad17b11ca02c0cf2a5a19de211dbdc5
numba>=0.53.1
7 changes: 6 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
numpy>=1.19
numpy==1.21.0
scipy>=1.5
networkx>=2.6.3
matplotlib>=3.5.1
autoray>=0.2.5
quimb @ git+https://github.com/jcmgray/quimb.git@c34bb13ccad17b11ca02c0cf2a5a19de211dbdc5
opt-einsum==3.3.0

0 comments on commit e762f8a

Please sign in to comment.