Skip to content

Commit 29dc2e2

Browse files
Change circuit TDVP to half-sweep (#6)
## Description This pull request changes TDVP to only perform one left-right half-sweep if simulating a circuit. ## Checklist: - [x] The pull request only contains commits that are related to it. - [x] I have added appropriate tests and documentation. - [x] I have made sure that all CI jobs on GitHub pass. - [x] The pull request introduces no new warnings and follows the project's style
2 parents 0cd0770 + 3cea0c1 commit 29dc2e2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/mqt/yaqs/core/methods/tdvp.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,9 @@ def two_site_tdvp(
519519
left_identity[i, a, i] = 1
520520
left_blocks[0] = left_identity
521521

522+
# Adjust simulation time step if simulation parameters require a unit time step.
522523
if isinstance(sim_params, (WeakSimParams, StrongSimParams)):
523-
sim_params.dt = 1
524+
sim_params.dt = 2
524525

525526
# Left-to-right sweep for sites 0 to L-2.
526527
for i in range(num_sites - 2):
@@ -544,12 +545,23 @@ def two_site_tdvp(
544545
numiter_lanczos,
545546
)
546547

548+
# Guarantees unit time at final site for circuits
549+
if isinstance(sim_params, (WeakSimParams, StrongSimParams)):
550+
sim_params.dt = 1
551+
547552
i = num_sites - 2
548553
merged_tensor = merge_mps_tensors(state.tensors[i], state.tensors[i + 1])
549554
merged_mpo = merge_mpo_tensors(hamiltonian.tensors[i], hamiltonian.tensors[i + 1])
550555
merged_tensor = update_site(
551556
left_blocks[i], right_blocks[i + 1], merged_mpo, merged_tensor, sim_params.dt, numiter_lanczos
552557
)
558+
# Only a single sweep is needed for circuits
559+
if isinstance(sim_params, (WeakSimParams, StrongSimParams)):
560+
state.tensors[i], state.tensors[i + 1] = split_mps_tensor(
561+
merged_tensor, "right", threshold=sim_params.threshold
562+
)
563+
return
564+
553565
state.tensors[i], state.tensors[i + 1] = split_mps_tensor(merged_tensor, "left", threshold=sim_params.threshold)
554566
right_blocks[i] = update_right_environment(
555567
state.tensors[i + 1], state.tensors[i + 1], hamiltonian.tensors[i + 1], right_blocks[i + 1]

0 commit comments

Comments
 (0)