Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/flush and canonical #33

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pytket/extensions/cutensornet/mps/mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ def canonicalise_tensor(self, pos: int, form: DirectionMPS) -> None:

# Update self.tensors
self.tensors[pos] = Q
self.tensors[pos].canonical_form = form
self.canonical_form[pos] = form # type: ignore
self.tensors[next_pos] = result
self.tensors[next_pos].canonical_form = None
self.canonical_form[next_pos] = None

def vdot(self, other: MPS) -> complex:
"""Obtain the inner product of the two MPS: ``<self|other>``.
Expand Down
3 changes: 3 additions & 0 deletions pytket/extensions/cutensornet/mps/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def simulate(
for g in sorted_gates:
mps.apply_gate(g)

# Apply the batched operations that are left (if any)
mps._flush()

# Apply the circuit's phase to the leftmost tensor (any would work)
mps.tensors[0] = mps.tensors[0] * np.exp(1j * np.pi * circuit.phase)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def test_circ_approx_explicit(circuit: Circuit) -> None:

# Check for MPSxMPO
mps_mpo = simulate(libhandle, circuit, ContractionAlg.MPSxMPO, chi=8)
assert np.isclose(mps_mpo.fidelity, 0.06, atol=1e-2)
assert np.isclose(mps_mpo.fidelity, 0.04, atol=1e-2)
assert mps_mpo.is_valid()
assert np.isclose(mps_mpo.vdot(mps_mpo), 1.0, atol=mps_mpo._atol)

Expand Down