MESAHub / mesa

Modules for Experiments in Stellar Astrophysics
http://mesastar.org
GNU Lesser General Public License v2.1
146 stars 39 forks source link

shmesa fix for issue #661 #663

Closed gautam-404 closed 5 months ago

gautam-404 commented 5 months ago

fix for issue #661

earlbellinger commented 5 months ago

You are great! Thank you for working on this.

Unfortunately there seems to be a bug. When I call shmesa test I get:

...
>>> test: shmesa change

SHMESA> DEBUG: Calling shmesa change with arguments: inlist_project pgstar_flag .false.
SHMESA> DEBUG: SHMESA> BACKING UP: inlist_project inlist_project.bak
SHMESA> DEBUG: Calling shmesa change with arguments: inlist_project initial_mass 1.2 Z 0.01 Zbase 0.01
SHMESA> DEBUG: SHMESA> BACKING UP: inlist_project inlist_project.bak
Error: Parameter 'Z' not found in the inlist 'inlist_project'.
SHMESA> DEBUG: SHMESA> RESTORING: inlist_project

Does shmesa test work on your machine?

earlbellinger commented 5 months ago

Oh actually this might be a problem with the tester rather than with your fix. Before it tried to change an inlist parameter Z which doesn't exist. Normal shmesa just doesn't make a change whereas this fix causes it to not go through. It's fine with it throwing an error though. In that case we should just change the test to have the proper initial_z rather than just Z then.

gautam-404 commented 5 months ago

Thanks for pointing that out. This should work now.

I am wondering if it is worth exploring the possibility to include functions like shmesa_set, shmesa_rm, shmesa_get to add, remove or echo inlist parameters. I've previously implemented this with Python. I am not sure if this is required or will be useful. Thoughts?

earlbellinger commented 5 months ago

Yes, please do! I think those would be really great additions. The only gotcha I can think of is taking care of getting the right namelist group.

wmwolf commented 5 months ago

The problem of identifying nameless groups is not trivial but it's doable. You can look at the source for MesaScript to see how it's done there (in MesaScript, you don't need to specify namelists; it handles sorting them for you). It might be hard to reproduce in bash alone, though. If I recall correctly, there is exactly one control that lives in multiple namelist groups. Maybe its logs_directory that is shared between binary_controls and controls, but I could be mistaken.

gautam-404 commented 5 months ago

I have achieved the desired results here. But I guess Python does make things easier. Doing the same with shell script is going to be way more challenging.

earlbellinger commented 5 months ago

Yes having dependencies is tough because then we have to support them - even sed isn't as cross-platform as I had thought 😂

But I just realized we can do all of these in a pretty straightforward way: