-
Notifications
You must be signed in to change notification settings - Fork 27
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
Optimize Wigner Function and Improve make_grid with @njit for Better Performance and Memory Efficiency #504
base: develop
Are you sure you want to change the base?
Conversation
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Code Suggestions ✨Explore these optional code suggestions:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #504 +/- ##
===========================================
- Coverage 89.77% 89.61% -0.16%
===========================================
Files 92 92
Lines 6072 6087 +15
===========================================
+ Hits 5451 5455 +4
- Misses 621 632 +11
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
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, bug_fix
Description
Wire
class intensors.py
by usingfield
for attribute initialization and improved dictionary comprehensions for better performance.make_grid
function inwigner.py
by preallocating arrays and optimizing the computation of coordinate matrices._wigner_discretized_iterative
function by precomputing exponential terms and square roots, reducing redundant calculations, and reusing matrices to enhance memory efficiency.Changes walkthrough 📝
tensors.py
Optimize tensor network wire and shape handling
mrmustard/math/tensor_networks/tensors.py
Wire
class attributes usingfield
.comprehensions.
AdjointView
andDualView
initializations.wigner.py
Enhance Wigner function computation efficiency
mrmustard/physics/wigner.py
make_grid
function with preallocated arrays._wigner_discretized_iterative
.