Skip to content

Commit cee34e6

Browse files
committed
optimize code
1 parent 0c61a9d commit cee34e6

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

examples/qudit_mps.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,7 @@ def main():
119119
mps = build_qutrit_circuit_mps(n=n, d=d, theta=theta)
120120
qc = build_qutrit_circuit_dense(n=n, d=d, theta=theta)
121121

122-
# Obtain statevectors (shape [-1])
123-
psi_mps = tc.backend.numpy(mps.wavefunction(form="default"))
124-
psi_dense = tc.backend.numpy(qc.wavefunction(form="default"))
125-
126-
# Normalize both just in case of tiny numerical drift
127-
def _norm(v):
128-
return v / np.linalg.norm(v)
129-
130-
psi_mps = _norm(psi_mps)
131-
psi_dense = _norm(psi_dense)
132-
133-
# \ell_\infty comparison: :math:`\max_i |(\psi_{\mathrm{MPS}} - \psi_{\mathrm{dense}})_i|`
134-
inf_err = np.max(np.abs(psi_mps - psi_dense))
135-
print(r"Max $|\Delta|$ between MPS and dense:", inf_err)
136-
137-
tol = 1e-10
138-
assert inf_err < tol, f"States differ too much: {inf_err} >= {tol}"
122+
np.testing.assert_allclose(mps.wavefunction(), qc.wavefunction())
139123
print("OK: MPSCircuit matches QuditCircuit for d=3 with unitary-applied gates.")
140124

141125

0 commit comments

Comments
 (0)