-
Notifications
You must be signed in to change notification settings - Fork 10
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
Environment variables #7
Comments
Should this be part of the existing assist_initialize() function or something separate? |
I'm not sure yet how to do this best... |
I made a first attempt at this. There is now an assist_ephem_init("/path/to/planets/file", "path/to/asteroids/file") function. This has to be called before assist_integrate() is called. There is probably a more graceful solution, but this is a start. I need to add a corresponding python function. |
Hanno, you'll need to add the paths to your ephemeris files for the unit tests to pass. |
Cool. Something like this is what I had in mind. I'm teaching today, but I'll think about how to make it more graceful/optional. I think it would make sense to look for the datafile in ASSIST_DIR/data by default. This is much easier in python where you can just have an optional argument. |
Matt- it looks like your changes are specific to 'mholman' ... does the user need to modify the code ad hoc, or do you intend to make this more general? Update: Nevemind - looks like that is only in the unit tests (and the problem.c) . |
Would it make sense to look for the ephemeris files in the default location and only call assist_ephem_init if they are not found? Or modify the function in forces.c to look in the default location ... |
The main ideas are (1) to avoid using environment variables, because users are not always familiar with those; and (2) to have the users explicitly call something like assist_ephem_init() with paths to the ephemeris files, so that any errors are very clear. |
So, by default assist looks for rebound installation in the same directory unless the REB_DIR environment variable is set. By the same token, cannot assist look for the files in assist/data by default before calling assist_ephem_init? The version with environment variables would look there, unless the environment variable were set to something else - so this would follow the same logic without requiring the user to set them, or to call assist_ephem_init, unless they choose to use some non-default location. |
I like the idea of @aryaakmal. We could have a char[] in |
(with a graceful exit and message if the files are not in the default location) |
The same logic should apply to the wrapper. Currently a pip install of assist will not find the ephemeris files unless the environment variable is set - or unless the files are in the default location and the following is set
|
I like the idea of storing the file names (or possibly pointers to the ephemeris objects) in assist_extras, but I am getting a little stuck on the order of things. With the current design, memory for a version of assist_extras is allocated when assist_integrate() calls assist_attach(), which then calls assist_initialize(). But that happens after assist_ephem_init(). |
I pushed another attempt at this, but it seems to have broken the benchmark unit test (and perhaps others). |
I agree, that order of function calls and memory management are a bit confusing. We struggled a lot with that with REBOUND and REBOUNDx too. One issue with having one function struct object = smth_create();
object->setting = 0;
smth_do(object);
smth_free(object); This is what I tried to replicate using the "plain interface". When it comes to memory management, the important question to always ask is: who owns the memory? The answer almost always helps with figuring when to allocate and free memory. For example, right now the space for the ephemeris data is allocated in |
This makes a lot of sense, but I think I am still missing something. Does this mean that there can only be one assist_extras struct? |
No quite the opposite. You could have multiple |
That's what I hoped! But how do we share the memory allocated by assist_jpl_int and then free it when all the runs are finished? |
I'm not sure about the best approach! I can see two options:
I think 2) would be the cleanest approach. It also works on multiple threads without any extra work. Do you think performance would be an issue? It depends how short or long individual integrations typically are. |
Somewhat related: I'm trying to understand a bit better what Wouldn't it make sense to just use the constants in the ephemeris file without this intermediate step? |
Option 2 is definitely cleaner, but there is some overhead in the initialization step, as you just saw. Option 1 seems easy enough, but I don't know what would be entailed in making that thread safe. |
It may be vestigial. I think the .h file may have superseded the original
jpl_init. Matt can you confirm?
…On Tue, Jan 24, 2023 at 11:54 AM Hanno Rein ***@***.***> wrote:
Somewhat related: I'm trying to understand a bit better what
assist_jpl_init does. It seems to read in names and values of constants
in the ephemeris file. But they are never used. Instead, the constants that
are hard coded in const.h are used. That file was generated with
dev_tools/constants/main.c.
Wouldn't it make sense to just use the constants in the ephemeris file
without this intermediate step?
—
Reply to this email directly, view it on GitHub
<#7 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOMJBQZADX5MN7ZSCI4ALUDWUACNZANCNFSM6AAAAAAT3LUMMQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The const.h file gives us easy access to the various constants, but it be done other ways. I believe @aryaakmal is correct that the version in jpl_init is vestigial. |
(I think it would be more consistent to read the constants from the ephemeris file directly. If the file ever changes, one would need to manually recreate Regarding the bigger picture. How about the following: We could create a new structure struct assist_ephem* ephem = assist_ephem_alloc("path to file");
...
xyz = assist_ephem_get_position(ephem, PLANET_MARS, 12345.55);
...
assist_ephem_free(ephem); After creating When one wants to do an integration then one creates an struct reb_simulation* sim = reb_create_simulation()
struct assist_ephem* ephem = assist_ephem_alloc("path to file");
struct assist_extras* extras = assist_extras_init(sim, ephem);
assist_integrate(extras, ...);
// or
reb_integrate(sim, 1234.56);
...
rebound_simulation_free(sim);
assist_extras_free(extras);
assist_ephem_free(ephem); One |
This is a nice solution, @hannorein. Thank you for sketching it out so clearly. I agree that the ephemeris access routines will be useful by themselves. I've been using all_ephem() for various things; it's accessible from python. We can make sure the new version is too. I think I can get started on this code, unless you or @aryaakmal would prefer to. |
Either way is fine. I should also have time tomorrow. One thing I’m not super happy with yet is the naming: |
unit_tests/benchmark has an issue where it appears that memory is being modified about being freed. The error says it's in rebound, but my bet is that it's something to do with the changes I made to assist_ephem_init(). Unfortunately, I haven't identified the problem yet. @hannorein, could you take a look? |
Will do. I'm implementing the stuff we talked about above right now. Let me know if that interferes with what you're doing and I should stop. |
No, it doesn't, but I will pause anyway. |
I suggest not using environment variables. I think this can be confusing to users who might not be familiar with the concept (one rarely comes across environment variables when using standard python packages).
Right now environment variables are only used in two locations to specify the path for data files. I suggest having an explicit
init
function that has to be called by the user before using assist. Something likeand similarly in python
If this function call results in an error for the user, then it's immediately clear what the issue is and how to fix it. It removes the stumbling block of learning what an environment variable is and how to set it.
Somewhat related to this, the metadata and the pointer to the data structures get stored in a static variable, which is effectively a global variable. If you only every read from that variable after it's initialized (which I think is the case), then the reading part is thread safe. However, the initialization is not. Imagine two threads both initializing this structure at the same time. It might work in practice, because it's a simple data structure, but there really should be a mutex around the init function if we want to claim it's thread safe (and to prevent we're accidentally loading in the data and allocating memory more than once).
The text was updated successfully, but these errors were encountered: