Replace examples with those from the second edition of the AMUSE book#1227
Replace examples with those from the second edition of the AMUSE book#1227rieder wants to merge 28 commits intoamusecode:mainfrom
Conversation
|
To be done:
|
|
If we do want to keep (some of) the old examples around, they should be in some directory that makes it clear that these are archived, and not updated. If they are still useful, they should be moved to the new structure. |
|
I don't see how the tests would depend on the examples, but I'll go and do a local build and run them all to check. I think pip packages, the PDF, and more examples should be separate Issues, so if it doesn't break the tests then I'll merge this, even if it isn't perfect I doubt it'll make things worse. |
5d45632 to
28b8cda
Compare
LourensVeen
left a comment
There was a problem hiding this comment.
I've pushed a commit to move the examples to src/amuse_examples and add a forward in src/amuse/examples, and make the whole thing an installable package like the others.
Looking at it again, I think it's probably better to put the actual examples into a subdirectory src/amuse_examples/amuse_examples, so that there's nothing else in the directory. Then we can symlink that to /examples, and if anyone plays with it on the command line then they're less likely to mess up the package definitions.
I've run the tests and this didn't break anything, but then I ran the examples themselves and found many problems, which I've added comments for.
There was a problem hiding this comment.
Crashes with
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/2017arXiv170307029H_Fig3.py", line 48, in <module>
from distinct_colours import get_distinct
ModuleNotFoundError: No module named 'distinct_colours'
There was a problem hiding this comment.
that is a remnant, should have been removed from the example.
There was a problem hiding this comment.
Ah, I actually found the file and put it in as part of my quick fixes. So that should come back out then.
There was a problem hiding this comment.
Won't run using amuse.examples.run:
Traceback (most recent call last):
File "<string>", line 1, in <module>
from amuse.examples import run ; run('supernova_grid')
~~~^^^^^^^^^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/__init__.py", line 55, in run
example.main()
~~~~~~~~~~~~^^
TypeError: main() missing 7 required positional arguments: 'stellar_mass', 'stellar_radius', 'core_mass', 'core_radius', 't_end', 'dt', and 'resolution'
There was a problem hiding this comment.
If I fix that, it crashes because we're trying to index grid.rho with something that isn't an int:
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse/examples/supernova_grid.py", line 17, in plot_grid
rho = grid.rho[:,:,halfway].value_in(units.g/units.cm**3)
~~~~~~~~^^^^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse/units/quantities.py", line 666, in __getitem__
return new_quantity(self._number[index], self.unit)
~~~~~~~~~~~~^^^^^^^
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
Lines 16 and 17 look suspicious to me, because there's an ellipsis in the first place on line 16, then halfway is used in the last place on line 17. But I don't know what this does.
There was a problem hiding this comment.
Fails because prepare_figure is missing.
| @@ -0,0 +1,55 @@ | |||
| from amuse.units import units | |||
| from amuse.community.seba import Seba | |||
| from seculartriple_tps import Seculartriple | |||
There was a problem hiding this comment.
seculartriple_tps is missing.
There was a problem hiding this comment.
that is part of the TRES package (https://github.com/silviatoonen/tres), maybe fail with an error message if this is not installed
There was a problem hiding this comment.
From a quick look, TRES needs to be updated anyway to work with the new AMUSE build system. Won't work as-is. One for my to-do list I guess, if I have the resources.
This seems to be the least ugly way to make python -m amuse.examples.x work
|
Moved the examples to Here's a list of example names that occur in the book, but seem to be missing from this PR: |
This file was deleted from the examples on purpose, the correct fix would be to remove the references to this. The replacement is using the matplotlib style for the book.
There was a problem hiding this comment.
need to remove these references instead.
The use of this is replaced with a dedicated matplotlib stylesheet, need to update examples to use this instead.
|
|
||
|
|
||
| def main(**kwargs): | ||
| calculate_core_temperature_density(**kwargs) |
There was a problem hiding this comment.
I'm getting
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse/examples/calculate_core_temperature_density.py", line 137, in <module>
main(**arguments.__dict__)
~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse/examples/calculate_core_temperature_density.py", line 132, in main
calculate_core_temperature_density(**kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
TypeError: calculate_core_temperature_density() got an unexpected keyword argument 'metalicity'
|
I've added back some more missing examples from and then there's |
|
Last missing files (and if found, where they are found): |
Existing examples are outdated, in some cases not working and often duplicated by others.
This replaces all examples from the "textbook", "syllabus" and "simple" directories with the complete set from the textbook (second edition).