-
Notifications
You must be signed in to change notification settings - Fork 29
Update wigner.py #593
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
base: develop
Are you sure you want to change the base?
Update wigner.py #593
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #593 +/- ##
===========================================
- Coverage 90.73% 90.53% -0.21%
===========================================
Files 101 101
Lines 5777 5798 +21
===========================================
+ Hits 5242 5249 +7
- Misses 535 549 +14
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
User description
Optimized Wigner Function Iterative Computation
Context:
The
_wigner_discretized_iterative
function calculates the Wigner function iteratively,which is essential for simulating quantum states in continuous variable quantum mechanics.
The original implementation had redundant operations, recalculations, and excessive memory
allocations, leading to performance bottlenecks. The
make_grid
function was also optimizedwith
@njit
to further enhance performance. This update improves both mathematical efficiencyand memory management.
Description of the Change:
avoid redundant calculations in each iteration.
the beginning and stored in an array. This reduces overhead inside nested loops.
function reuses memory by swapping matrices, which reduces memory allocations.
make_grid
Function:make_grid
function was updated to use@njit
to accelerate its performance.Q
andP
coordinate matrices are optimized to reduce overhead.sqrt_factor
is used to avoid redundant calculations inside nested loops.@njit
, the function is now compliant with Numba’s JIT compilation, allowingfaster and more efficient execution.
Benefits:
Improved Mathematical Efficiency:
values such as exponential terms and square roots.
the function more computationally efficient.
ensuring cache-friendlier execution.
Better Performance:
costly memory allocations, improving speed.
make_grid
: Using@njit
inmake_grid
improves both speed and memory efficiency,enabling seamless integration with the rest of the optimized functions.
Numba Compliance:
@njit
constraints,avoiding common type-related issues.
Possible Drawbacks:
increases memory usage at the beginning, but this is offset by performance gains during execution.
Related GitHub Issues:
NA
PR Type
Enhancement
Description
Optimized the iterative Wigner function computation for efficiency
Enhanced
make_grid
function for better performance and Numba compatibilityChanges walkthrough 📝
wigner.py
Optimize Wigner function and grid computation for speed and memory
mrmustard/physics/wigner.py
make_grid
to use explicit loops and precomputed factors forNumba JIT
_wigner_discretized_iterative
new ones
calculation