Skip to content

Add nsteps for Trotter expansion based on propagator error#1371

Open
arettig wants to merge 2 commits into
quantumlib:mainfrom
arettig:trotter_prop_error
Open

Add nsteps for Trotter expansion based on propagator error#1371
arettig wants to merge 2 commits into
quantumlib:mainfrom
arettig:trotter_prop_error

Conversation

@arettig

@arettig arettig commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #820. Currently we compute the number of steps in a Trotter expansion based on the desired error in the ground state energy. This PR adds a function to compute the number of steps based on the desired error in the propagator $U$ (which is different). This could be useful for certain use cases like dynamics.

New tests are also added to cover this new function.

The current implementation computes the number of steps needed
in a Trotter expansion to reach an error in the ground state energy.
This commit adds functionality to compute the number of steps determined
by the error in the propagator itself.
@arettig arettig requested a review from mhucka June 22, 2026 23:00

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces trotter_steps_required_propagator to calculate the number of Trotter steps required for accurate state evolution, updates trotter_steps_required to handle negative times correctly, and adds corresponding unit tests. The reviewer suggested adding input validation to both functions to prevent division-by-zero errors when precision parameters are non-positive, and ensuring that at least one step is returned for any non-zero simulation time when the error bound is zero.

Comment thread src/openfermion/circuits/trotter/trotter_error.py Outdated
Comment thread src/openfermion/circuits/trotter/trotter_error.py Outdated
Added checks to ensure the parameters and therefore output
of trotter_steps_required functions are physically meaningful.
Added several tests for edge cases of these functions.

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it would benefit for just a couple of small additions to value testing. Otherwise it looks good!

Comment on lines +205 to +209
if energy_precision <= 0:
raise ValueError("energy_precision must be strictly positive.")
if time == 0:
return 0
return max(1, int(ceil(abs(time) * sqrt(trotter_error_bound / energy_precision))))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also check that trotter_error_bound has reasonable values? E.g., that it's non-negative.

Comment on lines +236 to +241
if prop_precision <= 0:
raise ValueError("prop_precision must be strictly positive.")
if time == 0:
return 0
atime = abs(time)
return max(1, int(ceil(atime * sqrt(atime * trotter_error_bound / prop_precision))))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the comment above about trotter_error_bound

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect formula to calculate required Trotter steps

2 participants