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

Function for bounding number of Trotter steps required #121

Merged
merged 9 commits into from
Jul 21, 2017
22 changes: 21 additions & 1 deletion src/fermilib/utils/_trotter_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""Module to compute the second order Trotter error."""
from future.utils import iteritems

from math import sqrt
from math import sqrt, ceil
from scipy.linalg import expm

from fermilib.config import *
Expand Down Expand Up @@ -164,3 +164,23 @@ def error_bound(terms, tight=False):
error += 4.0 * abs(coefficient_a) * error_a ** 2

return error


def trotter_steps_required(trotter_error_bound, time, energy_precision):
"""Determine the number of Trotter steps for accurate simulation.

Args:
trotter_error_bound (float): Upper bound on Trotter error in the
state of interest.
time (float): The total simulation time.
energy_precision (float): Acceptable shift in state energy.

Returns:
The integer minimum number of Trotter steps required for
simulation to the desired precision.

Notes:
The number of Trotter steps required is an upper bound on the
true requirement, which may be lower. Calculated using
"""
return int(ceil(time ** 2 / energy_precision * trotter_error_bound))
13 changes: 13 additions & 0 deletions src/fermilib/utils/_trotter_error_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,16 @@ def test_error_bound_qubit_tight_less_than_loose_integration(self):
terms = [QubitOperator('X1'), QubitOperator('Y1'), QubitOperator('Z1')]
self.assertLess(error_bound(terms, tight=True),
error_bound(terms, tight=False))


class TrotterStepsRequiredTest(unittest.TestCase):
def test_trotter_steps_required(self):
self.assertEqual(trotter_steps_required(
trotter_error_bound=0.3, time=2.5, energy_precision=0.04), 47)

def test_trotter_steps_required_negative_time(self):
self.assertEqual(trotter_steps_required(
trotter_error_bound=0.1, time=3.3, energy_precision=0.11), 10)

def test_return_type(self):
self.assertIsInstance(trotter_steps_required(0.1, 0.1, 0.1), int)