From e762f8affe3ea6778d874daf406e8c694149db0a Mon Sep 17 00:00:00 2001 From: minatoyuichiro Date: Sun, 22 May 2022 02:31:51 +0000 Subject: [PATCH] update 2.0 --- README.md | 115 +++++++---------------------------- blueqat/_version.py | 3 +- blueqat/backends/__init__.py | 2 +- optional-requirements.txt | 6 +- requirements.txt | 7 ++- 5 files changed, 32 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index f8d5466..3120071 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 @@ -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 @@ -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]] @@ -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 diff --git a/blueqat/_version.py b/blueqat/_version.py index ee36a2d..c7649a8 100644 --- a/blueqat/_version.py +++ b/blueqat/_version.py @@ -14,5 +14,4 @@ """The version of blueqat.""" -__version__ = "1.0.4" -#__version__ = "0.5.0-dev" +__version__ = "2.0.0" \ No newline at end of file diff --git a/blueqat/backends/__init__.py b/blueqat/backends/__init__.py index 9e6fe8a..2383699 100644 --- a/blueqat/backends/__init__.py +++ b/blueqat/backends/__init__.py @@ -19,4 +19,4 @@ "draw": DrawCircuit, "quimb": Quimb, } -DEFAULT_BACKEND_NAME = "numpy" +DEFAULT_BACKEND_NAME = "quimb" diff --git a/optional-requirements.txt b/optional-requirements.txt index 77d2b0b..5d287cb 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -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 \ No newline at end of file +numba>=0.53.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 34e721b..093f1f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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