Skip to content

Implement heat.linalg.solve#2113

Open
brownbaerchen wants to merge 10 commits intomainfrom
features/2036-Implement_linalg_solve_from_NumPy
Open

Implement heat.linalg.solve#2113
brownbaerchen wants to merge 10 commits intomainfrom
features/2036-Implement_linalg_solve_from_NumPy

Conversation

@brownbaerchen
Copy link
Collaborator

Due Diligence

  • General:
  • Implementation:
    • unit tests: all split configurations tested
    • unit tests: multiple dtypes tested
    • NEW unit tests: MPS tested (1 MPI process, 1 GPU)
    • benchmarks: created for new functionality
    • benchmarks: performance improved or maintained
    • documentation updated where needed

Description

This function directly solves linear systems $Ax=b$ for $x$. It supports batched solving and $A$ and $b$ may only be distributed in non-batched axes.
The function simply passes the local data to pytorch and makes sure the input and output make sense for heat.

Note that pytorch allows to pass left=False in torch.linalg.solve in order to solve $xA=b$ instead. I didn't implement this here because I wasn't sure if it's needed and didn't want to bother. If you want to see this here, I suggest splitting #2036 into sub issues and not doing this as part of this PR. @GioPede, please let us know if you need this. As numpy.linalg.solve does not have this option, I assumed you don't.

I basically copy pasted the docstring from pytorch. I have a question @ClaudiaComito: I left some stuff in that is relevant not for the heat code, but only for the pytorch code that is called underneath. Specifically, I am thinking about the docstring including limitation of datatypes and raising RuntimeError if the matrix is not invertible. I don't like this because if it changes in pytorch, our documentation is just lying. On the other hand, users don't want to have to look up the torch documentation for the heat function they are using. What is the policy for this in heat?

Issue/s resolved: #2036

Changes proposed:

  • add heat.linalg.solve

Type of change

  • New feature

Does this change modify the behaviour of other functions? If so, which?

no

@brownbaerchen brownbaerchen added the HeatHub The HeatHub project, as part of Science Serve, aims to foster the Heat community. label Jan 22, 2026
@github-project-automation github-project-automation bot moved this to Todo in Roadmap Jan 22, 2026
@github-actions
Copy link
Contributor

Thank you for the PR!

@brownbaerchen brownbaerchen mentioned this pull request Jan 22, 2026
7 tasks
@github-actions
Copy link
Contributor

Thank you for the PR!

@github-actions
Copy link
Contributor

Thank you for the PR!

@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.67%. Comparing base (2ca98d5) to head (efcf4ae).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2113      +/-   ##
==========================================
+ Coverage   91.63%   91.67%   +0.04%     
==========================================
  Files          86       86              
  Lines       14005    14054      +49     
==========================================
+ Hits        12833    12884      +51     
+ Misses       1172     1170       -2     
Flag Coverage Δ
unit 91.67% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

@ClaudiaComito ClaudiaComito left a comment

Choose a reason for hiding this comment

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

Thanks a lot for addressing this @brownbaerchen . I have a few comments, see below. In general I'd rather avoid copy-pasting documentation from numpy or torch, although obviously they will be very similar. If we are copy-pasting, we should point out where from.

Also tagging @GioPede who requested the feature and might want to check it out as well.

# raise error if b is distributed in disallowed way
if b.is_distributed() and b.split == b_non_batched_axis:
raise ValueError(
f"b of shape {b.shape} with A of shape {A.shape} is split in {b.split} but may not be distributed in non-batched axis {b_non_batched_axis}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a bit obscure. How about "A and b are not distributed along the same batch axis: A.shape, A.split, b.shape, b.split...."

raise ValueError(f"Split of A and b must match, but got {A.split} and {b.split}")

# figure out what the output vector looks like
out_initalization = {"dtype": b.dtype, "device": b.device}
Copy link
Contributor

Choose a reason for hiding this comment

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

dtype should probably be types.promote_types(a.dtype, b.dtype)

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Roadmap Jan 28, 2026
@github-actions
Copy link
Contributor

Thank you for the PR!

@ClaudiaComito ClaudiaComito added this to the 1.8.0 milestone Jan 30, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

Thank you for the PR!

ClaudiaComito
ClaudiaComito previously approved these changes Mar 13, 2026
Copy link
Contributor

@ClaudiaComito ClaudiaComito left a comment

Choose a reason for hiding this comment

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

👍🏼

@github-project-automation github-project-automation bot moved this from In Progress to Merge queue in Roadmap Mar 13, 2026
@brownbaerchen
Copy link
Collaborator Author

@ClaudiaComito you need to reapprove after I resolved the merge conflict from moving the tests.

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

Labels

core features HeatHub The HeatHub project, as part of Science Serve, aims to foster the Heat community. linalg

Projects

Status: Merge queue

Development

Successfully merging this pull request may close these issues.

Implement linalg.solve from NumPy

2 participants