Skip to content

Commit

Permalink
Merge pull request #33 from CQCL/bugfix/flush_and_canonical
Browse files Browse the repository at this point in the history
Bugfix/flush and canonical
  • Loading branch information
PabloAndresCQ authored Sep 27, 2023
2 parents 63980ae + 527c39d commit a15c2c8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
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

0 comments on commit a15c2c8

Please sign in to comment.