Skip to content

Speedup QMCPy - #620

Open
sou-cheng-choi wants to merge 349 commits into
developfrom
speedup_choi
Open

Speedup QMCPy#620
sou-cheng-choi wants to merge 349 commits into
developfrom
speedup_choi

Conversation

@sou-cheng-choi

@sou-cheng-choi sou-cheng-choi commented Sep 13, 2026

Copy link
Copy Markdown
Member

See demo demos/performance_optimizations_demo.ipynb

As a result of these changes, All Tests on GitHub Actions reduced from ~25 minutes to <20 minutes.

sou-cheng-choi and others added 30 commits December 8, 2025 08:23
README.md:
* Corrected filename references.
* Removed references to non-existent files.

averaged_mae.py:
* Fixed PEP 8 spacing for parameter qp_seed and use the parameter in code.
*Enhanced documentation with.
*Removed an unused import.
* Cleaned up code by removing a commented-out block.
* Initial plan

* Add error log capture and display in parsl_test_runner.py

Co-authored-by: sou-cheng-choi <18743024+sou-cheng-choi@users.noreply.github.com>

* Simplify error logging by removing redundant stderr checks

Co-authored-by: sou-cheng-choi <18743024+sou-cheng-choi@users.noreply.github.com>

* Add error handling for log file reading operations

Co-authored-by: sou-cheng-choi <18743024+sou-cheng-choi@users.noreply.github.com>

---------

Co-authored-by: alegresor <agsorokin3@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sou-cheng-choi <18743024+sou-cheng-choi@users.noreply.github.com>
+ (self.interest_rate - self.volatility**2 / 2) * self.t_final
)
fp = self.start_price * norm.cdf(term1 / denom) - decay * norm.cdf(
fp = self.start_price * ndtr(term1 / denom) - decay * ndtr(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the ndtr and ndtri updates


def g(self, x):
z = np.einsum("...j,ij->...i", x, self.feature_array)
z = x @ self.feature_array.T

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

x may be three dimensional, in which case I think this will break. Also, I think np.einsum is usually as fast as possible, so maybe this line doesn't need to be changed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What has been changed here? Something new added?

z = norm.ppf(u)
quad = np.einsum("...i,ij,...j->...", z, self._corr_inv_minus_eye, z)
z = ndtri(u)
quad = ((z @ self._corr_inv_minus_eye) * z).sum(-1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment as earlier, I think this will break if z is three dimensional.

Comment on lines -152 to -176
n = len(t)

# Use most efficient method based on problem size
if n <= 200: # For small-medium matrices, broadcasting is fastest
t_sum = t[:, None] + t[None, :] # Shape: (n, n)
t_min = minimum.outer(t, t) # Shape: (n, n)
cov_matrix = S0_sq * exp(mu * t_sum) * (exp(self.diffusion * t_min) - 1)
else: # For larger matrices, use memory-efficient computation
cov_matrix = zeros((n, n))
exp_mu_t = exp(mu * t) # Pre-compute exp(mu * t_i)
exp_diff_t = exp(self.diffusion * t) # Pre-compute exp(diffusion * t_i)
for i in range(n): # Optimized symmetric matrix computation
cov_matrix[i, i] = S0_sq * exp_mu_t[i] ** 2 * (exp_diff_t[i] - 1)
for j in range(i + 1, n):
t_min_ij = min(t[i], t[j])
cov_ij = (
S0_sq
* exp_mu_t[i]
* exp_mu_t[j]
* (exp(self.diffusion * t_min_ij) - 1)
)
cov_matrix[i, j] = cov_ij
cov_matrix[j, i] = cov_ij # Symmetric

return cov_matrix

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to split this into small + large cases anymore? More efficient to just use simplified construction?

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.

4 participants