-
Notifications
You must be signed in to change notification settings - Fork 103
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
Questions about the c/c++ API #425
Comments
Thanks for raising this issue, this is very interesting! (we discussed your code in one of my group meetings a few weeks ago!). This is definitely something I'd like to support and a goal I had started working towards recently, so I'd be happy to help out with any changes to The current situation is as follows:
Currently,
I'm happy to help out and if this seems to be working, I can also work on getting Final note: the Also cc-ing @webbjj, because he may be interested in this conversation. |
Thank you for the very detailed description! I am happy that you are interesting to help me to implement the galpy API for petar. I have managed to write a simple interface to use force calculation function. I tested the MWPotential2014 and the result is consistent with the python output. I still have a few questions.
|
By the way, my current implementation of the interface can be found in Git:Petar. |
Glad to hear that you got a version to work! The units of inputs and outputs in the C code are the internal units described here. Converting to and from internal units is done in the Python part of Basically, you'd have to:
You can evaluate the potential with
The potentials are not documented in C; I would either direct people to the Python documentation (available online) or write an automated piece of code to transform the Python docstrings to C docstrings (because transferring them by hand will make it hard to keep them consistent). As I said above, I think the only good way for people to get
I think pip puts the
Currently, |
Thank you for the explanation! I have tried the _parse_pot (python3.6 pip installed galpy) and iterate all potentials listed in galpy.potential. This loop seems includes several function name that are not potential class. If I removed all functions, I still got several errors: <class 'galpy.potential.GaussianAmplitudeWrapperPotential.GaussianAmplitudeWrapperPotential'> WrapperPotentials are only supported in 3D and 2D It seems some potentials cannot be initialized with no arguments, or defaulted arguments are missing. Besides, some potential modules seems not import in init.py, thus cannot be used to initialize instances. Some potentials give empty pot_type and pot_args from _parse_pot, is this means that these potentials are not implemented in c code? Right now all these listed potentials I probably cannot used in the c interface. Besides, to generate a help function to show all pot_type and pot_args, It is necessary that the potential classes can support no arguments initalization. On the other hand, some potentials have very long list of arguments obtained from _parse_pot. Is it possible to initialize this potentials without manually inputting all arguments (using the default values instead) in the c interface? |
Some of these are objects that cannot be used on their own (wrappers need to wrap a potential), and some just don't have default arguments, because there isn't a useful default (interpolated potentials need to interpolate something, a moving object potential needs a moving object to initialize it).
Yes, these are not standard potentials, but just help with implementing other potentials.
These are either again not regular potentials ( There is a function
These are the potentials using interpolation or the triaxial ones that have to do a numerical integral using Gaussian quadrature. There's no way around this. |
I should perhaps add that I would imagine users of your code who want to use an external force from
I get the sense that you would want to avoid 1), but I wouldn't be supportive of that, because I think users should know they are using |
Thank your for the explanation. Now I understand how to do next. My propose is not exactly escaping step 1. I prefer to write a short python script as a PeTar tool that makes the step 1 much simpler. This is why I have the questions above. The script can print the pot_type and pot_args when users give a potential name and list all available potentials that can be used in the c interface. This can be done by one commander instead of opening python, importing libs and using functions to get the result step by step. Besides, the input style in the galpy c interface for PeTar is not exactly like the Python one. Thus the script help users to transfer output of _parse_pot to the Petar input style. The style of PeTar input is based on the GNU getopt (options with the format of -[char] [arguments] or --[string] [arguments]), thus I prefer to make the input of the pot_type and pot_args be consistent with the PeTar input style. As you can see, if a new user of Galpy try to touch the c interface, it is not straight forwards for them to get the information about _parse_pot. Even they finally successfully to get the idea to use _parse_pot, they will suffer the same problems like me and have questions about why some potentials are not working. Unless they check the Galpy documents in details or ask you directly, it is not easy to finger out what to do next. Thus, such kind of script can help users to avoid these techincal details. |
I have implemented the help script and it seems working well and I will continue more tests. I have a few more questions:
Do you mean these arguments can evolve in a simulation? From the _parse_pot, I can get a group of arguments for these type of potentials, what are the definitaion of these values? Like the values at time zero?
|
Okay, so it sounds like you would still have your users install I would say that I don't think most users should worry about the C interface, so I don't consider the difficulty in using it a big deal. I don't imagine that people using your code with I'm able to access
Does that not work for you? The long parameter lists don't evolve, they are just static numbers that define the potential ( For the If it were me, I would probably read the parameters of the potential from a file that contains them and then your interface to |
In petar -h and running time, users will see that they are using the galpy library. Also, the corresponding reference paper is shown. To use Galpy, users also need to install it first. So I think they will know that Galpy is used. The help script is a small tool, when users run it in terminal, it printed the I think many potential users of PeTar are interesting in the internal stellar dynamics of star clusters while they require an external potential to drive the tidal dissolution of the clusters. In most cases, they will probably only use the default Milkway potential or import existing potentials with default arguments. This help script is mostly useful for them to quickly set up the potential. Of course for users who want to design speficial potential models, they probably need to use the Galpy python interface to generate the instance first and then get type and argments. For the potential with a long argument list, I am also thinking to add an additional configure file to read and use help script to generate the configure file. Thanks for suggestion. For the In the filtered potential list from my help script, the |
Great, sounds like everything is working fine now then! For future reference, I think this is a list of changes to make to
I think that's all I took away from this thread, but please add if there is anything I missed. |
Today I have tried to simulate a star cluster by using MWPotential2014. The result looks reasonable. I will do more test and compare with the result from Galpy python. Thanks for all the help! I think your list of future reference is good. I have one more point to add. For the c interface, right now I include orbit/orbit_c_ext/integrateFullOrbit.h to get the parse_leapFuncArgs_Full function. I think you have mentioned that this declaration can be moved to galpy_potentials.h. Then, if only the force/potential calculation functions are needed in the interface, probably only the galpy_potentials.h is necessary to be included. This may simplify the interface. |
Great to hear that and thanks for the additional future point, I've added it to the list above. |
Hi Long Wang
This is awesome work. Apologies for not chiming in sooner. Incorporating
galpy potentials should really allow for petar to be used for a wide range
of problems.
If you want to test your code out further, as Jo mentioned we have an
interface for using galpy potentials in AMUSE already. So I could try
running the same set of initial conditions that you use with an AMUSE
integrator and we could compare. Alternatively, you could also create
whatever petar's default potential is in galpy and compare the results of
using galpy or not. Either way, if I can help I would be happy to!
Jeremy
…On Sat, Jul 25, 2020 at 8:55 AM lwang-astro ***@***.***> wrote:
Today I have tried to simulate a star cluster by using MWPotential2014.
The result looks reasonable. I will do more test and compare with the
result from Galpy python. Thanks for all the help!
I think your list of future reference is good. I have one more point to
add. For the c interface, right now I include
orbit/orbit_c_ext/integrateFullOrbit.h to get the parse_leapFuncArgs_Full
function. I think you have mentioned that this declaration can be moved to
galpy_potentials.h. Then, if only the force/potential calculation functions
are needed in the interface, probably only the galpy_potentials.h is
necessary to be included. This may simplify the interface.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#425 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB7AIYF5CAGMJV7GHX3UNIDR5LI5RANCNFSM4O5R7XXA>
.
|
Thank you for the suggestion. I have tried one test of tidal stream formation using the MWPotential2014 potential. The results of PeTar and Galpy seem agree with each other well. I have not yet tested other potentials. Since the interface is the same, I guess they should work correctly. |
Recently I have published a new N-body code, PeTar, aiming for simulating star clusters where many close encounters and binaries exist. The code is written in c++. I'd like to implement the external potentials as a tidal field for the clusters. I think galpy is a nice choice since it supports many kinds of potentials and also have c/c++ interface. I have tried to search the document and check the galpy_potential.h file, but not yet fully understand how to correctly implement the galpy as a c/c++ library. The major part of the documents seem to be for python interface. Is any test example writting in c/c++? That will be very helpful for me to understand the code.
What I'd like to have is a c/c++ API function to provide the 3D forces (x, y, z) for a given position. Besides, users can combine a group of potential functions like in the python interface.
The text was updated successfully, but these errors were encountered: