-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First qunatum glimpse & optimization of einsum with opt_einsum package
- Loading branch information
1 parent
729b196
commit 0fb4d52
Showing
10 changed files
with
190 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from syngular.quantum.circuit import Circuit | ||
from syngular.quantum.qbit import Qbit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
|
||
from syngular.tensor.matrix_product_state import MatrixProductState | ||
|
||
|
||
class Circuit: | ||
|
||
def __init__(self, size, bond=2, initializer="ground", structure=[]): | ||
self.initializer = initializer | ||
self.size = size | ||
|
||
self.structure = structure | ||
|
||
self.current_step = 0 | ||
self.current_state = None | ||
self.states = [] | ||
|
||
def run(self): | ||
pass | ||
|
||
def reset(self): | ||
if self.initializer == 'ground': | ||
self.current_state = MatrixProductState.zeros( | ||
input_shape=(2,)*self.size, | ||
bond_shape=(2,)*(self.size-1) | ||
) | ||
self.states.append(self.current_state) | ||
|
||
def step(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import numpy as np | ||
|
||
|
||
I = np.array([ | ||
[1., 0.], | ||
[0., 1.] | ||
]) | ||
|
||
X = np.array([ | ||
[0., 1.], | ||
[1., 0.] | ||
]) | ||
|
||
Y = np.array([ | ||
[0., -1.j], | ||
[1.j, 0.] | ||
]) | ||
|
||
Z = np.array([ | ||
[1., 0.], | ||
[0., -1.] | ||
]) | ||
|
||
H = 1/np.sqrt(2) * np.array([ | ||
[1., 1.], | ||
[1., -1.] | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
|
||
from syngular.tensor.matrix_product_state import MatrixProductState | ||
from syngular.quantum import gate | ||
|
||
class Qbit: | ||
|
||
def __init__(self, size): | ||
self.size = size | ||
self.dim = 2**self.size | ||
|
||
self.state = MatrixProductState.zeros((2,)*size, (2,)*(size-1)).decompose() | ||
self.state.real_parameters_number = self.dim | ||
|
||
for idx in range(self.state.sites_number-1): | ||
self.state.sites[idx][0] = gate.I | ||
self.state.sites[-1][0][0] = 1. | ||
|
||
def to_tensor(self): | ||
return self.state.to_tensor().reshape(self.dim) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from syngular.quantum import Circuit, Qbit | ||
import syngular.quantum.gate as gate | ||
|
||
circ = Circuit(initializer="ground", size=2, structure=[ | ||
(gate.X, 0) | ||
]) | ||
|
||
size = 30 | ||
|
||
ground = Qbit(size) | ||
|
||
# print(ground.to_tensor()) | ||
print(ground.state[(1,)*size]) | ||
print(ground.state[(0,)*size]) | ||
# print(ground.state.real_parameters_number, ground.state.parameters_number) | ||
# import numpy as np | ||
# from syngular.tensor import MatrixProductState | ||
# ground = np.zeros(shape=(2**size)) | ||
# ground[0] = 1 | ||
# print(ground) | ||
# qbit2 = MatrixProductState(ground.reshape((2,)*size), (3,)*(size-1)).decompose() | ||
# print(qbit2) | ||
# for site in qbit2.sites: | ||
# print('---') | ||
# print(site) | ||
# print(qbit2.to_tensor().reshape(2**size)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters