-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
94 additions
and
55 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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
from .canonical import is_canonical | ||
from .mps import MPS, check, norm, product_state | ||
from .canonical import check_mps, is_canonical | ||
from .mps import MPS | ||
from .norm import norm | ||
from .num_qubits import num_qubits | ||
from .product_state import product_state | ||
from .state_vector import state_vector | ||
from .svd import compact_svd, tensor_svd | ||
|
||
__all__ = [ | ||
is_canonical, | ||
check_mps, | ||
MPS, | ||
check, | ||
norm, | ||
product_state, | ||
norm, | ||
num_qubits, | ||
compact_svd, | ||
tensor_svd, | ||
product_state, | ||
state_vector, | ||
] |
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,11 @@ | ||
import numpy as np | ||
|
||
from .num_qubits import num_qubits | ||
|
||
|
||
def norm(m): | ||
A = np.identity(2) | ||
for t in range(num_qubits(m)): | ||
A = np.einsum("ij,jkl->ikl", A, m.tensors[t]) | ||
A = np.einsum("ijk,ijl->kl", A, m.tensors[t].conj()) | ||
return np.sqrt(np.trace(A)) |
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 @@ | ||
def num_qubits(m): | ||
return len(m.tensors) |
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,13 @@ | ||
import numpy as np | ||
|
||
from .mps import MPS | ||
|
||
|
||
def product_state(n, c=0): | ||
assert n > 0 | ||
tensors = [] | ||
for t in range(n): | ||
tensor = np.zeros((1, 2, 1)) | ||
tensor[0, (c >> (n - t - 1)) & 1, 0] = 1 | ||
tensors.append(tensor) | ||
return MPS(tensors) |
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 |
---|---|---|
@@ -1,21 +1,22 @@ | ||
import numpy as np | ||
|
||
from ..util.strops import letters, replace | ||
from .type import is_mps, num_qubits | ||
from .num_qubits import num_qubits | ||
from .type import is_mps | ||
|
||
|
||
def state_vector(mps): | ||
assert is_mps(mps) | ||
n = num_qubits(mps) | ||
v = mps.tensors[0] | ||
def state_vector(m): | ||
assert is_mps(m) | ||
n = num_qubits(m) | ||
v = m.tensors[0] | ||
for t in range(1, n): | ||
ss_v0 = letters()[: t + 2] | ||
ss_v1 = letters()[t + 1 : t + 4] | ||
ss_to = letters()[: t + 1] + letters()[t + 2 : t + 4] | ||
v = np.einsum(f"{ss_v0},{ss_v1}->{ss_to}", v, mps.tensors[t]) | ||
v = np.einsum(f"{ss_v0},{ss_v1}->{ss_to}", v, m.tensors[t]) | ||
v = v.reshape((2,) * n) | ||
ss_from = letters()[:n] | ||
ss_to = ss_from | ||
for p in range(n): | ||
ss_to = replace(ss_to, p, ss_from[mps.q2t[p]]) | ||
ss_to = replace(ss_to, p, ss_from[m.q2t[p]]) | ||
return np.einsum(f"{ss_from}->{ss_to}", v).reshape((2,) * n + (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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
from .mps import MPS | ||
|
||
|
||
def is_mps(mps): | ||
return isinstance(mps, MPS) | ||
|
||
|
||
def num_qubits(mps): | ||
return mps.num_qubits() | ||
def is_mps(m): | ||
return isinstance(m, MPS) |
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import numpy as np | ||
|
||
from ..util.strops import letters | ||
from .type import is_operator, num_qubits | ||
|
||
|
||
def hconj(op): | ||
assert is_operator(op) | ||
n = num_qubits(op) | ||
ss_from = letters()[: 2 * n] | ||
ss_to = ss_from[n : 2 * n] + ss_from[:n] | ||
return np.einsum("{}->{}".format(ss_from, ss_to), op).conjugate() | ||
ss_from = list(range(2 * n)) | ||
ss_to = list(range(n, 2 * n)) + list(range(n)) | ||
return np.einsum(op, ss_from, ss_to).conjugate() |
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