Skip to content
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

Improve beam and lattice importers #340

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

Hespe
Copy link
Member

@Hespe Hespe commented Feb 11, 2025

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

  • I have updated the changelog accordingly (required).
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.
  • I have reformatted the code and checked that formatting passes (required).
  • I have have fixed all issues found by flake8 (required).
  • I have ensured that all pytest tests pass (required).
  • I have run pytest on a machine with a CUDA GPU and made sure all tests pass (required).
  • I have checked that the documentation builds (required).

Note: We are using a maximum length of 88 characters per line.

@Hespe Hespe added the enhancement New feature or request label Feb 11, 2025
@Hespe Hespe self-assigned this Feb 11, 2025
@Hespe
Copy link
Member Author

Hespe commented Feb 11, 2025

Before finishing this PR, we should discuss the default behaviour of the beam importers that import numpy data. Right now there are actually in an inconsistent state:

  • When from_ocelot is used with default dtype=None, it uses the dtype of the numpy array passed to it. In my opinion this is the correct behaviour and it mimickes the dtype one obtains from torch.tensor when passing a numpy array. In fact, the behaviour is implemented using torch.as_tensor to determine the appropriate dtype.
  • from_astra on the other hand uses a default of dtype=torch.float32. This does not follow the automatic dtype selection we are implementing in this PR and thus definitely has to change. I see two possibilities:
    1. Simply change to dtype=None, making its behaviour identical to from_ocelot. This would be my preferred choice but it leads to a number of test failures currently. The problem is that the tests implicitly assume a beam of type torch.float32 and the solution would be to explicitly set dtype=torch.float32 in the tests while loading the beam.
    2. Change to dtype=None, but query torch.get_default_dtype in that case to determine the dtype. This makes the API mostly consistent with the current behaviour since torch.get_default_dtype() defaults to torch.float32 but deviates from how torch.tensor determines its dtype from numpy arrays.

In case we go for the second option, from_ocelot should be updated in the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adopt automatic type scheme for importers
1 participant