Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wistaria committed Dec 10, 2023
1 parent 5b66525 commit 1d3a03b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion example/qpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def qpe(n, u, v):

if __name__ == "__main__":
n = 3
phi = 2 * np.pi * (1 / 3)
phi = 2 * np.pi * 0.7
u = q.op.p(phi)
v = q.sv.zero()
v = q.apply(v, q.op.x())
Expand Down
14 changes: 7 additions & 7 deletions example/test_qpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@

def test_qpe():
n = 3
phi = 2 * np.pi * (1 / 8)
phi = 2 * np.pi * 0.7
u = q.op.p(phi)

v = q.sv.zero()
v = q.apply(v, q.op.x())
v = q.sv.product_state([q.sv.zero(n), v])
v = qpe(n, u, v)
prob = q.probability(v, list(range(n)))
assert prob[4] == approx(1)
assert prob[0] == approx(0)
assert prob[0] == approx(0.02159321892578291)
assert prob[3] == approx(0.5775210180698607)

v = q.mps.zero(1)
v = q.apply(v, q.op.x())
v = q.mps.product_state([q.mps.zero(n), v])
v = qpe(n, u, v)
prob = q.probability(v, list(range(n)))
assert prob[4] == approx(1)
assert prob[0] == approx(0)
assert prob[0] == approx(0.02159321892578291)
assert prob[3] == approx(0.5775210180698607)

v = q.mps.zero(1, mps=q.mps.projector_mps)
v = q.apply(v, q.op.x())
v = q.mps.product_state([q.mps.zero(n, mps=q.mps.projector_mps), v])
v = qpe(n, u, v)
prob = q.probability(v, list(range(n)))
assert prob[4] == approx(1)
assert prob[0] == approx(0)
assert prob[0] == approx(0.02159321892578291)
assert prob[3] == approx(0.5775210180698607)


if __name__ == "__main__":
Expand Down
16 changes: 8 additions & 8 deletions src/qailo/mps/svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def compact_svd(A, nkeep=None, tol=1e-12):


def tensor_svd(T, partition, canonical="center", nkeep=None, tol=1e-12):
legs0 = len(partition[0])
legs1 = len(partition[1])
assert len(T.shape) == legs0 + legs1
legsL = len(partition[0])
legsR = len(partition[1])
assert len(T.shape) == legsL + legsR
assert sorted(partition[0] + partition[1]) == list(range(len(T.shape)))
dims0 = [T.shape[i] for i in partition[0]]
dims1 = [T.shape[i] for i in partition[1]]
dimsL = [T.shape[i] for i in partition[0]]
dimsR = [T.shape[i] for i in partition[1]]
m = np.einsum(T, partition[0] + partition[1]).reshape(
np.prod(dims0), np.prod(dims1)
np.prod(dimsL), np.prod(dimsR)
)
S, U, V = compact_svd(m, nkeep=nkeep, tol=tol)
L = U
Expand All @@ -32,6 +32,6 @@ def tensor_svd(T, partition, canonical="center", nkeep=None, tol=1e-12):
L = np.einsum("ij,j->ij", L, S)
else:
raise ValueError
L = L.reshape(dims0 + [S.shape[0]])
R = R.reshape([S.shape[0]] + dims1)
L = L.reshape(dimsL + [S.shape[0]])
R = R.reshape([S.shape[0]] + dimsR)
return L, R

0 comments on commit 1d3a03b

Please sign in to comment.