Implement electron range module with bindings and model definitions#189
Open
PiotrPich2024 wants to merge 3 commits into
Open
Implement electron range module with bindings and model definitions#189PiotrPich2024 wants to merge 3 commits into
PiotrPich2024 wants to merge 3 commits into
Conversation
…ge-and-other-similar-modules
Contributor
There was a problem hiding this comment.
Pull request overview
This PR splits electron-range functionality out of the stopping extension into a dedicated pyamtrack.electron_range module, updates package exports/build targets, and retargets several tests to the new entry point. In the codebase, this is a public-API refactor around how electron range calculations and model helpers are exposed to Python.
Changes:
- Added a new
electron_rangeextension module with bindings, model helpers, and amax_range()API plus an in-moduleelectron_range()alias. - Removed the old electron-range bindings from
pyamtrack.stoppingand updated package/build wiring to ship the new module. - Migrated most tests to import from
pyamtrack.electron_range, while the oldstoppingtests were commented out.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_stopping.py |
Legacy stopping electron-range tests were commented out. |
tests/test_stopping_models.py |
Legacy stopping model-helper tests were commented out. |
tests/test_multidim_input.py |
Switched multidimensional-input tests to the new module. |
tests/test_function_behavior.py |
Switched behavior tests to the new module. |
tests/test_electron_range_models.py |
Added model tests for the new electron-range module. |
tests/test_cartesian_product.py |
Switched cartesian-product tests to the new module. |
src/stopping/stopping_bindings.cpp |
Replaced previous stopping bindings with an empty placeholder module. |
src/pyamtrack/__init__.py |
Exported the new electron_range module from the package. |
src/electron_range/electron_range.h |
Renamed model map/function declaration to the new module terminology. |
src/electron_range/electron_range.cpp |
Renamed implementation symbols from electron_range to max_range. |
src/electron_range/electron_range_bindings.cpp |
Added the new Python bindings and docs for the electron-range module. |
CMakeLists.txt |
Added electron_range to the extension build/install targets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+9
to
+10
| // Placeholder: stopping power functions will be added here later | ||
| // For now, the module is empty but must be defined for the build system to work |
Comment on lines
+84
to
+87
| Raises | ||
| ------ | ||
| ValueError | ||
| If the model name is not recognized. |
Comment on lines
+1
to
+34
| # import numpy as np | ||
| # import pytest | ||
|
|
||
| # import pyamtrack.stopping | ||
|
|
||
|
|
||
| # @pytest.fixture | ||
| # def electron_energy_MeV(): | ||
| # """Fixture providing the electron energy in MeV for tests.""" | ||
| # return 1000.0 | ||
|
|
||
|
|
||
| # def test_electron_range(electron_energy_MeV): | ||
| # """Test the electron_range function for various inputs.""" | ||
| # range_m = pyamtrack.stopping.electron_range(electron_energy_MeV) | ||
| # assert range_m > 0.01, "Expected positive range for positive energy." | ||
|
|
||
|
|
||
| # def test_electron_range_air_vs_water(electron_energy_MeV): | ||
| # """Test the electron_range function for air and water.""" | ||
| # range_air = pyamtrack.stopping.electron_range(electron_energy_MeV, pyamtrack.materials.air) | ||
| # range_water = pyamtrack.stopping.electron_range(electron_energy_MeV, pyamtrack.materials.water_liquid) | ||
| # assert range_air > range_water, "Expected range in air to be larger than in water." | ||
|
|
||
|
|
||
| # def test_material_assignment(electron_energy_MeV): | ||
| # """Test the material assignment by ID.""" | ||
| # range_default = pyamtrack.stopping.electron_range(electron_energy_MeV) | ||
| # range_material_name = pyamtrack.stopping.electron_range(electron_energy_MeV, pyamtrack.materials.water_liquid) | ||
| # assert range_default == range_material_name, "Expected range to be the same for default and material name." | ||
| # range_material_id = pyamtrack.stopping.electron_range(electron_energy_MeV, 1) | ||
| # assert range_default == range_material_id, "Expected range to be the same for default and material ID." | ||
|
|
||
|
|
Comment on lines
+1
to
+5
| # import numpy as np | ||
| # import pytest | ||
|
|
||
| import pyamtrack.materials | ||
| import pyamtrack.stopping as stopping | ||
| # import pyamtrack.materials | ||
| # import pyamtrack.stopping as stopping |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP
Added electron range module and moved electron range from stopping to new module, updated cmakelist and init