ip: section 2 task 3 Hamiltonian Sys Dynamics #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a class ExpectedResults to compute the expectation value of X_0 for a Trotterized Ising Hamiltonian evolution. The results are collected over multiple time steps and Trotter steps.
🚀 Changes Introduced
• Implements ExpectedResults class for structured execution.
• Computes expectation values using Trotterized evolution circuits.
• Measures all qubits before retrieving results.
• Compiles circuits once per step to reduce redundant computations.
• Ensures imaginary part of expectation value is minimal.
🛠️ Next Steps / Known Issues
• Performance Issue:
• Execution is slow, especially for large N and many Trotter steps.
• Possible optimizations:
• Reduce redundant circuit re-compilations.
• Investigate more efficient expectation value computation.
• Parallelize circuit execution if possible.
• Code Generalization:
• Currently designed for X_0 expectation only.
• Consider refactoring to allow flexible observables.
✅ How to Test
1. Run the script and verify expectation values are computed correctly.
2. Check that no imaginary parts exceed 1e-8.
3. Validate the output using print_results() and graph_results().