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

[feature] Always canonicalise MPS before 2q gate #82

Merged
merged 1 commit into from
Apr 3, 2024
Merged
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
19 changes: 4 additions & 15 deletions pytket/extensions/cutensornet/structured_state/mps_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,16 @@ def _apply_2q_gate(self, positions: tuple[int, int], gate: Op) -> MPSxGate:
l_pos = min(positions)
r_pos = max(positions)

# Always canonicalise. Even in the case of exact simulation (no truncation)
# canonicalisation may reduce the bond dimension (thanks to reduced QR).
self.canonicalise(l_pos, r_pos)

# Figure out the new dimension of the shared virtual bond
new_dim = 2 * min(
self.get_virtual_dimensions(l_pos)[0],
self.get_virtual_dimensions(r_pos)[1],
)

# Canonicalisation may be required if `new_dim` is larger than `chi`
# or if set by `truncation_fidelity`
if new_dim > self._cfg.chi or self._cfg.truncation_fidelity < 1:
# If truncation required, convert to canonical form before
# contracting. Avoids the need to apply gauge transformations
# to the larger tensor resulting from the contraction.
self.canonicalise(l_pos, r_pos)

# Since canonicalisation may change the dimension of the bonds,
# we need to recalculate the value of `new_dim`
new_dim = 2 * min(
self.get_virtual_dimensions(l_pos)[0],
self.get_virtual_dimensions(r_pos)[1],
)

# Load the gate's unitary to the GPU memory
gate_unitary = gate.get_unitary().astype(dtype=self._cfg._complex_t, copy=False)
gate_tensor = cp.asarray(gate_unitary, dtype=self._cfg._complex_t)
Expand Down