-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# (C) Copyright IBM 2023. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Trotter simulation utilities.""" | ||
|
||
from __future__ import annotations | ||
|
||
from collections.abc import Iterator | ||
|
||
|
||
def simulate_trotter_step_iterator( | ||
n_terms: int, time: float, order: int = 0 | ||
) -> Iterator[tuple[int, float]]: | ||
if order == 0: | ||
for i in range(n_terms): | ||
yield i, time | ||
else: | ||
yield from simulate_trotter_step_iterator_symmetric(n_terms, time, order) | ||
|
||
|
||
def simulate_trotter_step_iterator_symmetric( | ||
n_terms: int, time: float, order: int | ||
) -> Iterator[tuple[int, float]]: | ||
if order == 1: | ||
for i in range(n_terms - 1): | ||
yield i, time / 2 | ||
yield n_terms - 1, time | ||
for i in reversed(range(n_terms - 1)): | ||
yield i, time / 2 | ||
else: | ||
split_time = time / (4 - 4 ** (1 / (2 * order - 1))) | ||
for _ in range(2): | ||
yield from simulate_trotter_step_iterator_symmetric( | ||
n_terms, split_time, order - 1 | ||
) | ||
yield from simulate_trotter_step_iterator_symmetric( | ||
n_terms, time - 4 * split_time, order - 1 | ||
) | ||
for _ in range(2): | ||
yield from simulate_trotter_step_iterator_symmetric( | ||
n_terms, split_time, order - 1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters