fieldsmith 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fieldsmith-0.1.4/LICENSE +83 -0
- fieldsmith-0.1.4/PKG-INFO +107 -0
- fieldsmith-0.1.4/README.md +151 -0
- fieldsmith-0.1.4/README_PYPI.md +84 -0
- fieldsmith-0.1.4/pyproject.toml +75 -0
- fieldsmith-0.1.4/setup.cfg +4 -0
- fieldsmith-0.1.4/src/fieldsmith/__init__.py +10 -0
- fieldsmith-0.1.4/src/fieldsmith/cad/__init__.py +0 -0
- fieldsmith-0.1.4/src/fieldsmith/cad/lids.py +156 -0
- fieldsmith-0.1.4/src/fieldsmith/cad/plates.py +111 -0
- fieldsmith-0.1.4/src/fieldsmith/cad/rails.py +263 -0
- fieldsmith-0.1.4/src/fieldsmith/cad/slabs.py +273 -0
- fieldsmith-0.1.4/src/fieldsmith/callbacks.py +140 -0
- fieldsmith-0.1.4/src/fieldsmith/configurations/__init__.py +8 -0
- fieldsmith-0.1.4/src/fieldsmith/configurations/dome_config.py +107 -0
- fieldsmith-0.1.4/src/fieldsmith/configurations/halbach_system_config.py +86 -0
- fieldsmith-0.1.4/src/fieldsmith/configurations/magnet_configuration.py +145 -0
- fieldsmith-0.1.4/src/fieldsmith/configurations/setup_npy.py +94 -0
- fieldsmith-0.1.4/src/fieldsmith/evaluation/__init__.py +17 -0
- fieldsmith-0.1.4/src/fieldsmith/evaluation/core.py +223 -0
- fieldsmith-0.1.4/src/fieldsmith/evaluation/monte_carlo.py +269 -0
- fieldsmith-0.1.4/src/fieldsmith/field_simulations/__init__.py +11 -0
- fieldsmith-0.1.4/src/fieldsmith/field_simulations/cuboid.py +152 -0
- fieldsmith-0.1.4/src/fieldsmith/field_simulations/demagnetization.py +145 -0
- fieldsmith-0.1.4/src/fieldsmith/field_simulations/dipole.py +131 -0
- fieldsmith-0.1.4/src/fieldsmith/field_simulations/rectangular_prism.py +275 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/__init__.py +18 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/cap_lattice.py +123 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/collision.py +196 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/cube_axes.py +132 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/dome.py +100 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/halbach_ring.py +122 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/halbach_system.py +181 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/lsq_seed.py +208 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/roi.py +109 -0
- fieldsmith-0.1.4/src/fieldsmith/geometry/roma.py +148 -0
- fieldsmith-0.1.4/src/fieldsmith/logger.py +99 -0
- fieldsmith-0.1.4/src/fieldsmith/magnet_geometry_verifier.py +397 -0
- fieldsmith-0.1.4/src/fieldsmith/metrics.py +73 -0
- fieldsmith-0.1.4/src/fieldsmith/models/__init__.py +17 -0
- fieldsmith-0.1.4/src/fieldsmith/models/dome/__init__.py +6 -0
- fieldsmith-0.1.4/src/fieldsmith/models/dome/model.py +202 -0
- fieldsmith-0.1.4/src/fieldsmith/models/dome/position_model.py +109 -0
- fieldsmith-0.1.4/src/fieldsmith/models/halbach_ring/__init__.py +5 -0
- fieldsmith-0.1.4/src/fieldsmith/models/halbach_ring/model.py +181 -0
- fieldsmith-0.1.4/src/fieldsmith/models/halbach_systems/__init__.py +5 -0
- fieldsmith-0.1.4/src/fieldsmith/models/halbach_systems/model.py +143 -0
- fieldsmith-0.1.4/src/fieldsmith/models/small_halbach.py +393 -0
- fieldsmith-0.1.4/src/fieldsmith/objectives.py +175 -0
- fieldsmith-0.1.4/src/fieldsmith/point_sampler.py +131 -0
- fieldsmith-0.1.4/src/fieldsmith/train_loop.py +104 -0
- fieldsmith-0.1.4/src/fieldsmith/visualizations/__init__.py +17 -0
- fieldsmith-0.1.4/src/fieldsmith/visualizations/matplotlib_2d.py +316 -0
- fieldsmith-0.1.4/src/fieldsmith/visualizations/plotly_3d.py +568 -0
- fieldsmith-0.1.4/src/fieldsmith/visualizations/system_3d.py +250 -0
- fieldsmith-0.1.4/src/fieldsmith.egg-info/PKG-INFO +107 -0
- fieldsmith-0.1.4/src/fieldsmith.egg-info/SOURCES.txt +94 -0
- fieldsmith-0.1.4/src/fieldsmith.egg-info/dependency_links.txt +1 -0
- fieldsmith-0.1.4/src/fieldsmith.egg-info/requires.txt +16 -0
- fieldsmith-0.1.4/src/fieldsmith.egg-info/top_level.txt +1 -0
- fieldsmith-0.1.4/tests/test_cad_export.py +61 -0
- fieldsmith-0.1.4/tests/test_callbacks.py +237 -0
- fieldsmith-0.1.4/tests/test_collision.py +261 -0
- fieldsmith-0.1.4/tests/test_cuboid.py +243 -0
- fieldsmith-0.1.4/tests/test_demagnetization.py +152 -0
- fieldsmith-0.1.4/tests/test_dipole.py +201 -0
- fieldsmith-0.1.4/tests/test_dome_config.py +216 -0
- fieldsmith-0.1.4/tests/test_dome_geometry.py +239 -0
- fieldsmith-0.1.4/tests/test_dome_model.py +201 -0
- fieldsmith-0.1.4/tests/test_dome_position_model.py +126 -0
- fieldsmith-0.1.4/tests/test_evaluation.py +129 -0
- fieldsmith-0.1.4/tests/test_halbach_ring.py +111 -0
- fieldsmith-0.1.4/tests/test_halbach_ring_model.py +199 -0
- fieldsmith-0.1.4/tests/test_halbach_system_config.py +129 -0
- fieldsmith-0.1.4/tests/test_halbach_system_model.py +140 -0
- fieldsmith-0.1.4/tests/test_head_lattice.py +86 -0
- fieldsmith-0.1.4/tests/test_logger.py +198 -0
- fieldsmith-0.1.4/tests/test_lsq_seed.py +182 -0
- fieldsmith-0.1.4/tests/test_lumc_halbach.py +185 -0
- fieldsmith-0.1.4/tests/test_magnet_configuration.py +315 -0
- fieldsmith-0.1.4/tests/test_magnet_geometry_verifier.py +586 -0
- fieldsmith-0.1.4/tests/test_matplotlib_2d.py +144 -0
- fieldsmith-0.1.4/tests/test_metrics.py +28 -0
- fieldsmith-0.1.4/tests/test_monte_carlo.py +124 -0
- fieldsmith-0.1.4/tests/test_objectives.py +214 -0
- fieldsmith-0.1.4/tests/test_paper_scripts.py +59 -0
- fieldsmith-0.1.4/tests/test_plates.py +94 -0
- fieldsmith-0.1.4/tests/test_plotly_3d.py +162 -0
- fieldsmith-0.1.4/tests/test_point_sampler.py +58 -0
- fieldsmith-0.1.4/tests/test_rectangular_prism.py +211 -0
- fieldsmith-0.1.4/tests/test_roi.py +54 -0
- fieldsmith-0.1.4/tests/test_roma_geometry.py +245 -0
- fieldsmith-0.1.4/tests/test_setup_npy.py +68 -0
- fieldsmith-0.1.4/tests/test_small_halbach.py +47 -0
- fieldsmith-0.1.4/tests/test_system_3d.py +213 -0
- fieldsmith-0.1.4/tests/test_train_loop.py +224 -0
fieldsmith-0.1.4/LICENSE
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
FRAUNHOFER »fieldsmith« LICENSE FOR SCIENTIFIC NON-COMMERCIAL RESEARCH PURPOSES
|
|
2
|
+
(hereinafter referred to as »License«)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V., Hansastraße 27c, 80686 Munich, Germany (“Fraunhofer”), is an organization for application-oriented research and pursues exclusively and directly non-profit purposes.
|
|
6
|
+
The Fraunhofer Institute for Digital Medicine MEVIS (MEVIS) develops real-world software solutions for image and data supported early detection, diagnosis, and therapy and has developed the software »fieldsmith« as part of its activities. Fraunhofer has the rights to use and exploit the Software (as defined in clause 1), with the exception of those components that constitute third-party software within the meaning of this License. The Software is currently in the development stage; it shall therefore not be used for medical purposes.
|
|
7
|
+
|
|
8
|
+
Fraunhofer is willing to grant research institutions limited rights to use the Software for testing and evaluation purposes for scientific non-commercial research purposes only without the right to sublicense or transfer the Software; the use for other purposes is not allowed«.
|
|
9
|
+
|
|
10
|
+
1
|
|
11
|
+
Definitions
|
|
12
|
+
|
|
13
|
+
»Field of Use« is defined as scientific non-commercial research including the right to publish test and/or evaluation results.
|
|
14
|
+
|
|
15
|
+
»Internal Purposes« means the Licensee’s internal purposes of testing and using the Software in the Field of Use.
|
|
16
|
+
»Licensee« means a research institution granted a right to use the Software for scientific non-commercial research purposes under this License.
|
|
17
|
+
|
|
18
|
+
»Third Party Software« means any computer program provided by third parties as licensors and/or authors/right holders under their own license terms, including but not limited to open source software as defined by the Open Source Initiative (www.opensource.org). Third-party software used or included is listed in the “THIRD PARTY LICENSES” file in the repository of this Software. If Fraunhofer software is listed as Third Party Software in the file, Fraunhofer shall also be deemed to be a third party and the software shall be deemed to be Third Party Software for the purposes of this License.
|
|
19
|
+
|
|
20
|
+
»Object Code« is the intermediate result of a compiler or translation process of the Source Code of the Software and is not subject of this License.
|
|
21
|
+
|
|
22
|
+
»Source Code« means the code of the Software in the version of the programming language(s).
|
|
23
|
+
|
|
24
|
+
»Software« means the computer program made available by Fraunhofer in the Github repository under »fieldsmith«.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
2
|
|
28
|
+
License
|
|
29
|
+
|
|
30
|
+
2.1
|
|
31
|
+
Subject to the terms and conditions of this License, the Licensee’s acceptance of the terms of this License and the Licensee’s compliance with the provisions of this License, Fraunhofer hereby grants the Licensee the perpetual, non-exclusive, non-sublicensable, non-transferable and royalty-free right, limited in terms of content to Internal Purposes in the Field of Use only, to use the Software on Licensee's computers, i.e. to store and load it permanently or temporarily, to display it and to run it, even to the extent that duplications are necessary for this purpose. The use of results generated or obtained by using the Software for diagnostic or therapeutic purposes is not permitted under this License.
|
|
32
|
+
|
|
33
|
+
2.2
|
|
34
|
+
The right under clause 2.1 includes the right to modify the Software. Licensee shall not reproduce and distribute copies of the Software (neither in Source Code nor in Object Code form) on any medium, with or without modifications.
|
|
35
|
+
|
|
36
|
+
2.3
|
|
37
|
+
No further rights of use or exploitation are granted to the Licensee. Fraunhofer shall retain all intellectual property rights, including software, patents and know-how unless expressly licensed hereunder. The Licensee agrees to refrain from any further use or commercialization of the Software not permitted by the license granted herein.
|
|
38
|
+
|
|
39
|
+
2.4
|
|
40
|
+
Fraunhofer does not grant any rights to Third Party Software to the Licensee, therefore the Licensee must independently ensure proper licensing under their respective applicable license terms. The Third Party Software may be copyrighted in favor of a third party or third parties, e.g., in favor of the authors indicated in the copyright notices included in the corresponding source files or other materials provided together with the Third Party Software, e.g., an open source software. The “THIRD PARTY LICENSES” file in the repository of the Software contains the Third Party Software used by Fraunhofer together with the Software. Fraunhofer does not warrant or represent that Third Party Software is free of errors or claims or fit for a particular purpose. Before using the Third Party Software, the Licensee shall independently verify whether the use of the Third Party Software is permissible and suitable for its purposes. The Licensee undertakes not to use the Software or parts thereof in a way that would result in the Software or parts thereof being licensable under an open source software license. A right of use which allows the Licensee to make the Software or parts thereof available to third parties in its original or edited form as free software in the sense of open source is expressly not granted under this License.
|
|
41
|
+
|
|
42
|
+
3
|
|
43
|
+
Liability, Warranty
|
|
44
|
+
|
|
45
|
+
3.1
|
|
46
|
+
Except in cases of intentional and grossly negligent conduct, Fraunhofer, its legal representatives, trustees, officers and employees shall not be liable for direct or indirect, material or immaterial loss or damage of any kind arising from the License or the use of the Software; this applies, among other things, but not exclusively, to loss of goodwill, loss of production, computer failures or errors, loss of data or economic loss or damage, even if Fraunhofer has been notified of the possibility of such loss or damage.
|
|
47
|
+
|
|
48
|
+
3.2
|
|
49
|
+
Irrespective of clause 3.1, Fraunhofer shall only be liable within the scope of statutory product liability to the extent that the respective provisions are applicable to the Software.
|
|
50
|
+
|
|
51
|
+
3.3
|
|
52
|
+
The Licensee indemnifies Fraunhofer against any claims of third parties, including related costs such as reasonable lawyers' fees and court costs, asserted against Fraunhofer in connection with the Licensee's exercise of the license or due to a breach of the terms of this License by the Licensee.
|
|
53
|
+
|
|
54
|
+
3.4
|
|
55
|
+
Regarding the Software Fraunhofer has not complied with any regulatory requirements (including norms or other standards) applicable to medical devices, in-vitro diagnostics or medicinal products.
|
|
56
|
+
|
|
57
|
+
Fraunhofer has not provided any technical documentation, quality assurance, risk management or risk analysis (e.g. in accordance with EN ISO 13485, 14971 or 62304).
|
|
58
|
+
|
|
59
|
+
Fraunhofer makes no representations regarding the therapeutic, diagnostic or other medical purpose, usability, performance or safety of the Software or its suitability for conformity assessment purposes of medical devices or in-vitro diagnostics. Fraunhofer is not responsible for the usability and quality of the Software being unaffected if implemented in other results or used in conjunction with other results.
|
|
60
|
+
|
|
61
|
+
Licensee understands and accepts that the Software is considered research software and is not a medical device. Furthermore, the Licensee knows and accepts that all research results generated or obtained by using the Software may not be used for diagnostic or therapeutic purposes. Furthermore, the Software is not intended for use in therapeutic or diagnostic applications on humans or for other medical purposes or for any other purpose.
|
|
62
|
+
|
|
63
|
+
3.5
|
|
64
|
+
Insofar as the Software was or is being developed in a publicly funded project, Fraunhofer shall in any case remain entitled to fulfill its obligations under the relevant grant conditions, notwithstanding any other provisions in this Agreement. In particular, Licensee understands and accepts that the German Federal Ministry of Health and its subordinate authorities are granted a non-exclusive, non-transferable, royalty-free right to use the Software in all ways and unlimited in terms of location, time and content.
|
|
65
|
+
|
|
66
|
+
4
|
|
67
|
+
Limited warranty
|
|
68
|
+
|
|
69
|
+
This License is granted free of charge and thus constitutes a gift. Accordingly, any warranty is excluded. The Software is a work in progress. The Software is not complete and may therefore contain errors ("bugs"), as is inherent in this type of development.
|
|
70
|
+
|
|
71
|
+
5
|
|
72
|
+
No Trademarks
|
|
73
|
+
|
|
74
|
+
This License does not grant permission to use the trade names, trademarks, service marks or product names of Fraunhofer.
|
|
75
|
+
|
|
76
|
+
6
|
|
77
|
+
Applicable Law, Place of Jurisdiction
|
|
78
|
+
|
|
79
|
+
6.1
|
|
80
|
+
The laws of the Federal Republic of Germany apply exclusively to the exclusion of the conflict of law provisions and the United Nations Convention on Contracts for the International Sale of Goods (CISG).
|
|
81
|
+
|
|
82
|
+
6.2
|
|
83
|
+
The courts of Munich are hereby agreed as place of jurisdiction for all disputes arising from or connected with the License.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fieldsmith
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Fast dipole-field based magnet optimization utilities.
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: manifold3d>=3.4
|
|
9
|
+
Requires-Dist: matplotlib
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Requires-Dist: plotly>=6.8.0
|
|
12
|
+
Requires-Dist: rtree>=1.4
|
|
13
|
+
Requires-Dist: scipy
|
|
14
|
+
Requires-Dist: shapely>=2.1
|
|
15
|
+
Requires-Dist: torch==2.11.0
|
|
16
|
+
Requires-Dist: trimesh>=4.11
|
|
17
|
+
Requires-Dist: wandb
|
|
18
|
+
Provides-Extra: cpu
|
|
19
|
+
Requires-Dist: torch==2.11.0; extra == "cpu"
|
|
20
|
+
Provides-Extra: cu128
|
|
21
|
+
Requires-Dist: torch==2.11.0; extra == "cu128"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# FieldSmith
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+

|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
FieldSmith is a PyTorch-based framework for designing, optimizing, and evaluating permanent-magnet arrays. It provides differentiable magnetic-field models, reusable geometry and sampling components, gradient-based optimization workflows, and tools for checking designs under realistic physics and manufacturing tolerances.
|
|
31
|
+
|
|
32
|
+
The package focuses on Halbach rings and multi-ring systems, the ROMA geometry, and open-cap/dome arrays for low-field MRI applications.
|
|
33
|
+
|
|
34
|
+
## Disclaimer
|
|
35
|
+
|
|
36
|
+
The software is not qualified for use as a medical product or as part thereof. Provided 'as is' without specific verification or validation.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Capabilities
|
|
40
|
+
|
|
41
|
+
- Build and optimize geometries such as Halbach rings, multi-ring, ROMA, and dome magnet arrays.
|
|
42
|
+
- Calculate differentiable fields with fast dipole or finite cuboid models.
|
|
43
|
+
- Run gradient-based optimization of magnet orientations, positions, and other parameters within the PyTorch framework.
|
|
44
|
+
- Evaluate field strength, peak-to-peak homogeneity, and RMS deviation.
|
|
45
|
+
- Run Monte Carlo studies of manufacturing tolerances.
|
|
46
|
+
- Move magnets within bounded boxes under a clearance penalty, and export a design as printable plates with seats, lids and fastening rails.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
FieldSmith requires Python 3.11 or newer.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python -m pip install fieldsmith
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For a specific CPU or CUDA build, install a compatible version of PyTorch first,
|
|
58
|
+
then install FieldSmith. See the [PyTorch installation guide](https://pytorch.org/get-started/locally/).
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
61
|
+
|
|
62
|
+
Compute the magnetic field at two points outside a single cubic magnet. Positions
|
|
63
|
+
are in meters, volumes are in cubic meters, and the returned field is in tesla.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import torch
|
|
67
|
+
|
|
68
|
+
from fieldsmith.configurations import MagnetConfiguration
|
|
69
|
+
from fieldsmith.evaluation import field_at_points
|
|
70
|
+
|
|
71
|
+
magnet_size_m = 0.01
|
|
72
|
+
configuration = MagnetConfiguration(
|
|
73
|
+
positions=torch.zeros((1, 3), dtype=torch.float64),
|
|
74
|
+
orientations=torch.tensor([[1.0, 0.0, 0.0]], dtype=torch.float64),
|
|
75
|
+
volumes=torch.tensor([magnet_size_m**3], dtype=torch.float64),
|
|
76
|
+
remanence=1.2,
|
|
77
|
+
metadata={"magnet_size_m": magnet_size_m},
|
|
78
|
+
)
|
|
79
|
+
points = torch.tensor([[0.03, 0.0, 0.0], [0.0, 0.03, 0.0]], dtype=torch.float64)
|
|
80
|
+
field = field_at_points(configuration, points, field_model="cuboid")
|
|
81
|
+
print(field)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The kernels preserve PyTorch gradients and support point chunking to control memory use. Field points can come from a Cartesian grid, a masked region of interest, or an arbitrary point cloud. Optimization objectives include exact and smoothed peak-to-peak homogeneity, RMS deviation, field-strength constraints, and collision penalties.
|
|
85
|
+
|
|
86
|
+
## Outputs and checkpoints
|
|
87
|
+
|
|
88
|
+
`TrainLoop` stores periodic `MagnetConfiguration` checkpoints at
|
|
89
|
+
`configurations/epoch_<N>.pt` under the configured logger directory, including
|
|
90
|
+
when W&B logging is disabled.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
FieldSmith is distributed under the **FRAUNHOFER »fieldsmith« LICENSE FOR
|
|
95
|
+
SCIENTIFIC NON-COMMERCIAL RESEARCH PURPOSES**. The full license is included in
|
|
96
|
+
the package as `LICENSE`.
|
|
97
|
+
|
|
98
|
+
## Citing
|
|
99
|
+
|
|
100
|
+
As soon as the paper is published the citing template of the software-related paper will be added here.
|
|
101
|
+
|
|
102
|
+
## Support or contact
|
|
103
|
+
|
|
104
|
+
For support with regard to the **FieldSmith** software please contact:
|
|
105
|
+
|
|
106
|
+
- Kostiantyn Lavronenko: [kostiantyn.lavronenko@mevis.fraunhofer.de](mailto:kostiantyn.lavronenko@mevis.fraunhofer.de)
|
|
107
|
+
- Marian Frei: [marian.frei@lfb.rwth-aachen.de](mailto:marian.frei@lfb.rwth-aachen.de)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# FieldSmith
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
<!--  -->
|
|
8
|
+
|
|
9
|
+
FieldSmith is a PyTorch-based framework for designing, optimizing, and evaluating permanent-magnet arrays. It provides differentiable magnetic-field models, reusable geometry and sampling components, gradient-based optimization workflows, and tools for checking designs under realistic physics and manufacturing tolerances.
|
|
10
|
+
|
|
11
|
+
The repository currently focuses on Halbach rings and multi-ring systems, the ROMA geometry, and open-cap/dome arrays for low-field MRI applications.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## Disclaimer
|
|
16
|
+
|
|
17
|
+
The software is not qualified for use as a medical product or as part thereof. Provided 'as is' without specific verification or validation.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Capabilities
|
|
21
|
+
|
|
22
|
+
- Build and optimize geometries such as Halbach rings, multi-ring, ROMA, and dome magnet arrays.
|
|
23
|
+
- Calculate differentiable fields with fast dipole or finite cuboid models.
|
|
24
|
+
- Run gradient-based optimization of magnet orientations, positions, and other parameters within the PyTorch framework.
|
|
25
|
+
- Evaluate field strength, peak-to-peak homogeneity, and RMS deviation.
|
|
26
|
+
- Run Monte Carlo studies of manufacturing tolerances.
|
|
27
|
+
- Move magnets within bounded boxes under a clearance penalty, and export a design as printable plates with seats, lids and fastening rails.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
FieldSmith requires Python 3.11 or newer. Choose one of the mutually exclusive
|
|
33
|
+
PyTorch backends when installing the environment.
|
|
34
|
+
|
|
35
|
+
Using [uv](https://docs.astral.sh/uv/):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
git clone https://github.com/FraunhoferMEVIS/fieldsmith.git
|
|
39
|
+
cd fieldsmith
|
|
40
|
+
uv sync --extra cpu
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For CUDA 12.8 instead, run:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
uv sync --extra cu128
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Include the same extra in subsequent `uv run` commands, for example
|
|
50
|
+
`uv run --extra cpu python scripts/example_system_optimization.py`. The CPU
|
|
51
|
+
installation avoids the CUDA runtime packages. GPU execution is recommended for
|
|
52
|
+
dense three-dimensional or cuboid calculations; use double precision for results
|
|
53
|
+
around 1,000 ppm or below.
|
|
54
|
+
|
|
55
|
+
By default, uv also installs the `dev` dependency group for the repository's
|
|
56
|
+
paper scripts, notebooks, and tests. A pip install of the built package uses
|
|
57
|
+
the runtime requirements from `[project]` in `pyproject.toml`. To try those
|
|
58
|
+
runtime requirements from a clone, run `uv sync --locked --no-dev --extra cpu`.
|
|
59
|
+
|
|
60
|
+
## Available workflows
|
|
61
|
+
|
|
62
|
+
| Workflow | Entry point |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| Generic Halbach system example | `scripts/example_system_optimization.py` |
|
|
65
|
+
| Single Halbach ring angle optimization | `scripts/paper/run_fast_halbach_ring_optimisation.py` |
|
|
66
|
+
| Three-stage small Halbach system optimization | `scripts/paper/run_small_halbach_optimisation.py` |
|
|
67
|
+
| ROMA multi-ring system angle optimization | `scripts/paper/run_fast_roma_optimisation.py` |
|
|
68
|
+
| Open-cap/dome system optimization | `scripts/run_dome_optimisation.py` |
|
|
69
|
+
| Printable plates, lids and rails | `scripts/export_plates.py` |
|
|
70
|
+
| Manufacturing Monte Carlo | `scripts/run_monte_carlo_evaluation.py` |
|
|
71
|
+
|
|
72
|
+
See [docs/examples.md](docs/examples.md) for command examples and the geometry
|
|
73
|
+
verification workflow.
|
|
74
|
+
|
|
75
|
+
## Reproducing the paper
|
|
76
|
+
|
|
77
|
+
Every optimization reported in the paper can be rerun from this repository. The
|
|
78
|
+
[reproduction guide](docs/reproduction.md) gives each command with its parameters,
|
|
79
|
+
random seeds and expected numbers.
|
|
80
|
+
|
|
81
|
+
| Paper result | Entry point |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| Single-ring orientation benchmark | `scripts/paper/run_fast_halbach_ring_optimisation.py` |
|
|
84
|
+
| Ring-radius comparison of GA, DE and gradient descent | `scripts/paper/lumc/` |
|
|
85
|
+
| Small Halbach demonstrator | `scripts/paper/run_small_halbach_optimisation.py` |
|
|
86
|
+
| ROMA after least-squares initialization, 321 ppm | `scripts/paper/roma_from_lsq_seed.sh` |
|
|
87
|
+
| ROMA refinement at the published seats, 332 ppm | `scripts/paper/roma_refined_at_seats.sh` |
|
|
88
|
+
| Cylinder opened along one side, 672 ppm | `scripts/paper/opened_cylinder.sh` |
|
|
89
|
+
| Dome-shaped head array, 980 ppm | `scripts/paper/dome_head_array.sh` |
|
|
90
|
+
|
|
91
|
+
Paper experiment entry points live in `scripts/paper/`, with the LUMC comparison
|
|
92
|
+
scripts in `scripts/paper/lumc/`. Run them from the repository root using the
|
|
93
|
+
commands in the reproduction guide. Shared optimization, input-building, and
|
|
94
|
+
stage helpers remain in `scripts/` and `scripts/stages/`.
|
|
95
|
+
The four shell scripts in `scripts/paper/` run without arguments and build their own inputs.
|
|
96
|
+
The four reported designs are in `data/paper/` as `.pt` configurations.
|
|
97
|
+
|
|
98
|
+
## Outputs and checkpoints
|
|
99
|
+
|
|
100
|
+
Runs write to timestamped directories below `logs/` unless an output directory is
|
|
101
|
+
specified. `TrainLoop` stores periodic `MagnetConfiguration` checkpoints as
|
|
102
|
+
`configurations/epoch_<N>.pt`, including when W&B logging is disabled. Specialized
|
|
103
|
+
workflows may also write a final configuration, summary JSON, CSV history, and
|
|
104
|
+
plots; the command prints the selected output directory. The four shell scripts in
|
|
105
|
+
`scripts/paper/` write their stages and the final design to `runs/<name>/`.
|
|
106
|
+
|
|
107
|
+
## Documentation
|
|
108
|
+
|
|
109
|
+
- [Architecture and component responsibilities](docs/architecture.md)
|
|
110
|
+
- [Field models and their mathematical formulation](docs/field_models.md)
|
|
111
|
+
- [Workflow examples](docs/examples.md)
|
|
112
|
+
- [Reference experiment reproduction](docs/reproduction.md)
|
|
113
|
+
- [Magnet configuration and checkpoint conventions](docs/conventions.md)
|
|
114
|
+
- [Testing guide](docs/testing.md)
|
|
115
|
+
|
|
116
|
+
The kernels preserve PyTorch gradients and support point chunking to control memory use. Field points can come from a Cartesian grid, a masked region of interest, or an arbitrary point cloud. Optimization objectives include exact and smoothed peak-to-peak homogeneity, RMS deviation, field-strength constraints, and collision penalties.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
Run the tests from the repository root:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
uv run --extra cpu pytest
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
To generate an HTML coverage report, run:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
uv run --extra cpu pytest tests --cov=fieldsmith --cov-report=html
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## License and third-party data
|
|
134
|
+
|
|
135
|
+
**FieldSmith** software lies under the [*FRAUNHOFER »fieldsmith« LICENSE FOR SCIENTIFIC NON-COMMERCIAL RESEARCH PURPOSES*](LICENSE).
|
|
136
|
+
|
|
137
|
+
The additional notice for the utilized software in [`docs/licences/`](docs/licences/) summarizes the:
|
|
138
|
+
|
|
139
|
+
- [MIT License](docs/licences/LUMC-LowFieldMRI.txt) for the `scripts/paper/lumc/homogeneityOptimization.py` and `scripts/paper/lumc/lumc_halbach.py`. Corresponding repository: [HalbachOptimization](https://github.com/LUMC-LowFieldMRI/HalbachOptimisation).
|
|
140
|
+
- [CERN Open Hardware Licence Version 2](docs/licences/OSII_rc2.1.txt) for the files describing the ROMA arrangement in `data/osii_rc2.1/`. Corresponding repository: [OSII/rc/2.1](https://gitlab.com/osii/magnet/30cm-halbach-magnet/-/tree/rc/2.1?ref_type=heads)
|
|
141
|
+
|
|
142
|
+
## Citing
|
|
143
|
+
|
|
144
|
+
As soon as the paper is published the citing template of the software-related paper will be added here.
|
|
145
|
+
|
|
146
|
+
## Support or contact
|
|
147
|
+
|
|
148
|
+
For support with regard to the **FieldSmith** software please contact:
|
|
149
|
+
|
|
150
|
+
- Kostiantyn Lavronenko: [kostiantyn.lavronenko@mevis.fraunhofer.de](mailto:kostiantyn.lavronenko@mevis.fraunhofer.de)
|
|
151
|
+
- Marian Frei: [marian.frei@lfb.rwth-aachen.de](mailto:marian.frei@lfb.rwth-aachen.de)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# FieldSmith
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
FieldSmith is a PyTorch-based framework for designing, optimizing, and evaluating permanent-magnet arrays. It provides differentiable magnetic-field models, reusable geometry and sampling components, gradient-based optimization workflows, and tools for checking designs under realistic physics and manufacturing tolerances.
|
|
8
|
+
|
|
9
|
+
The package focuses on Halbach rings and multi-ring systems, the ROMA geometry, and open-cap/dome arrays for low-field MRI applications.
|
|
10
|
+
|
|
11
|
+
## Disclaimer
|
|
12
|
+
|
|
13
|
+
The software is not qualified for use as a medical product or as part thereof. Provided 'as is' without specific verification or validation.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Capabilities
|
|
17
|
+
|
|
18
|
+
- Build and optimize geometries such as Halbach rings, multi-ring, ROMA, and dome magnet arrays.
|
|
19
|
+
- Calculate differentiable fields with fast dipole or finite cuboid models.
|
|
20
|
+
- Run gradient-based optimization of magnet orientations, positions, and other parameters within the PyTorch framework.
|
|
21
|
+
- Evaluate field strength, peak-to-peak homogeneity, and RMS deviation.
|
|
22
|
+
- Run Monte Carlo studies of manufacturing tolerances.
|
|
23
|
+
- Move magnets within bounded boxes under a clearance penalty, and export a design as printable plates with seats, lids and fastening rails.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
FieldSmith requires Python 3.11 or newer.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python -m pip install fieldsmith
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For a specific CPU or CUDA build, install a compatible version of PyTorch first,
|
|
35
|
+
then install FieldSmith. See the [PyTorch installation guide](https://pytorch.org/get-started/locally/).
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
Compute the magnetic field at two points outside a single cubic magnet. Positions
|
|
40
|
+
are in meters, volumes are in cubic meters, and the returned field is in tesla.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import torch
|
|
44
|
+
|
|
45
|
+
from fieldsmith.configurations import MagnetConfiguration
|
|
46
|
+
from fieldsmith.evaluation import field_at_points
|
|
47
|
+
|
|
48
|
+
magnet_size_m = 0.01
|
|
49
|
+
configuration = MagnetConfiguration(
|
|
50
|
+
positions=torch.zeros((1, 3), dtype=torch.float64),
|
|
51
|
+
orientations=torch.tensor([[1.0, 0.0, 0.0]], dtype=torch.float64),
|
|
52
|
+
volumes=torch.tensor([magnet_size_m**3], dtype=torch.float64),
|
|
53
|
+
remanence=1.2,
|
|
54
|
+
metadata={"magnet_size_m": magnet_size_m},
|
|
55
|
+
)
|
|
56
|
+
points = torch.tensor([[0.03, 0.0, 0.0], [0.0, 0.03, 0.0]], dtype=torch.float64)
|
|
57
|
+
field = field_at_points(configuration, points, field_model="cuboid")
|
|
58
|
+
print(field)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The kernels preserve PyTorch gradients and support point chunking to control memory use. Field points can come from a Cartesian grid, a masked region of interest, or an arbitrary point cloud. Optimization objectives include exact and smoothed peak-to-peak homogeneity, RMS deviation, field-strength constraints, and collision penalties.
|
|
62
|
+
|
|
63
|
+
## Outputs and checkpoints
|
|
64
|
+
|
|
65
|
+
`TrainLoop` stores periodic `MagnetConfiguration` checkpoints at
|
|
66
|
+
`configurations/epoch_<N>.pt` under the configured logger directory, including
|
|
67
|
+
when W&B logging is disabled.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
FieldSmith is distributed under the **FRAUNHOFER »fieldsmith« LICENSE FOR
|
|
72
|
+
SCIENTIFIC NON-COMMERCIAL RESEARCH PURPOSES**. The full license is included in
|
|
73
|
+
the package as `LICENSE`.
|
|
74
|
+
|
|
75
|
+
## Citing
|
|
76
|
+
|
|
77
|
+
As soon as the paper is published the citing template of the software-related paper will be added here.
|
|
78
|
+
|
|
79
|
+
## Support or contact
|
|
80
|
+
|
|
81
|
+
For support with regard to the **FieldSmith** software please contact:
|
|
82
|
+
|
|
83
|
+
- Kostiantyn Lavronenko: [kostiantyn.lavronenko@mevis.fraunhofer.de](mailto:kostiantyn.lavronenko@mevis.fraunhofer.de)
|
|
84
|
+
- Marian Frei: [marian.frei@lfb.rwth-aachen.de](mailto:marian.frei@lfb.rwth-aachen.de)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fieldsmith"
|
|
3
|
+
license-files = ["LICENSE"]
|
|
4
|
+
version = "0.1.4"
|
|
5
|
+
description = "Fast dipole-field based magnet optimization utilities."
|
|
6
|
+
readme = "README_PYPI.md"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"manifold3d>=3.4",
|
|
10
|
+
"matplotlib",
|
|
11
|
+
"numpy",
|
|
12
|
+
"plotly>=6.8.0",
|
|
13
|
+
"rtree>=1.4",
|
|
14
|
+
"scipy",
|
|
15
|
+
"shapely>=2.1",
|
|
16
|
+
"torch==2.11.0",
|
|
17
|
+
"trimesh>=4.11",
|
|
18
|
+
"wandb",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
cpu = [
|
|
23
|
+
"torch==2.11.0",
|
|
24
|
+
]
|
|
25
|
+
cu128 = [
|
|
26
|
+
"torch==2.11.0",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[tool.uv]
|
|
30
|
+
conflicts = [
|
|
31
|
+
[
|
|
32
|
+
{ extra = "cpu" },
|
|
33
|
+
{ extra = "cu128" },
|
|
34
|
+
],
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[tool.uv.sources]
|
|
38
|
+
torch = [
|
|
39
|
+
{ index = "pytorch-cpu", extra = "cpu" },
|
|
40
|
+
{ index = "pytorch-cu128", extra = "cu128" },
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[[tool.uv.index]]
|
|
44
|
+
name = "pytorch-cpu"
|
|
45
|
+
url = "https://download.pytorch.org/whl/cpu"
|
|
46
|
+
explicit = true
|
|
47
|
+
|
|
48
|
+
[[tool.uv.index]]
|
|
49
|
+
name = "pytorch-cu128"
|
|
50
|
+
url = "https://download.pytorch.org/whl/cu128"
|
|
51
|
+
explicit = true
|
|
52
|
+
|
|
53
|
+
[build-system]
|
|
54
|
+
requires = ["setuptools>=69"]
|
|
55
|
+
build-backend = "setuptools.build_meta"
|
|
56
|
+
|
|
57
|
+
[dependency-groups]
|
|
58
|
+
dev = [
|
|
59
|
+
"deap>=1.4.3",
|
|
60
|
+
"ipykernel>=7.3.0",
|
|
61
|
+
"magpylib>=5.2,<6",
|
|
62
|
+
"nbformat>=4.2.0",
|
|
63
|
+
"pytest>=9.1.1",
|
|
64
|
+
"pytest-cov>=7.1.0",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[tool.setuptools.packages.find]
|
|
68
|
+
where = ["src"]
|
|
69
|
+
|
|
70
|
+
[tool.pytest.ini_options]
|
|
71
|
+
pythonpath = ["src", "."]
|
|
72
|
+
markers = [
|
|
73
|
+
"unit: Fast tests for isolated units of behavior.",
|
|
74
|
+
"validation: Tests that validate numerical or system behavior against reference results.",
|
|
75
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
|
|
2
|
+
# -----------------------------------------------------------------------------
|
|
3
|
+
# This file initializes the FieldSmith magnet optimization package.
|
|
4
|
+
#
|
|
5
|
+
# __init__.py
|
|
6
|
+
# Kostiantyn Lavronenko
|
|
7
|
+
# 22.06.2026
|
|
8
|
+
# -----------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
"""FieldSmith magnet optimization utilities."""
|
|
File without changes
|