Coder Social home page Coder Social logo

nrpy's Introduction

Python CI

NRPy 2: Python/SymPy-Based Code Generation for Numerical Relativity... and Beyond!

Quick start, Step 1:

pip install nrpy

Quick start, Step 2: Choose a project to build.

BlackHoles@Home infrastructure (standalone): Choose a project, run the provided command, then follow the instructions for compiling & running the generated C code.

  • Wave equation solver
    • Cartesian coordinates:
      python3 -m nrpy.examples.wave_equation_cartesian
      
    • Curvilinear coordinates:
      python3 -m nrpy.examples.wave_equation_curvilinear
      
  • General relativity
    • Two black holes collide:
      python3 -m nrpy.examples.two_blackholes_collide
      
    • Black hole spectroscopy:
      python3 -m nrpy.examples.blackhole_spectroscopy
      
    • Spinning black hole:
      python3 -m nrpy.examples.spinning_blackhole
      
    • Binary black hole initial data, courtesy NRPyElliptic:
      python3 -m nrpy.examples.nrpyelliptic_conformally_flat
      

Einstein Toolkit infrastructure: Choose a project to build, run the provided command. Check the examples/et_* directory for a ThornList and parameter file. Thorns will be output to project/

  • Wave equation solver
    • Cartesian coordinates, with Carpet AMR infrastructure:
      python3 -m nrpy.examples.carpet_wavetoy_thorns
      
  • General relativity: Generate Baikal and BaikalVacuum thorns
    • Cartesian coordinates, with Carpet AMR infrastructure:
      python3 -m nrpy.examples.carpet_baikal_thorns
      

superB infrastructure: Choose a project, run the provided command, then follow the instructions for installing Charm++, compiling and running the generated C++ code.

  • General relativity
    • Two black holes collide:
      python3 -m nrpy.examples.superB_two_blackholes_collide
      

Quick Start, Step 3

  1. If working with a BlackHoles@Home project: follow the directions at the end of the code generation, starting with "Now go into [directory name] and type make to build, then [executable] to run. Parameter file can be found in [parameter filename]."
  2. Parameter files are text files, making it easy to adjust simulation parameters.
  3. In addition, parameters can be set at the command line. For example, wavetoy has a parameter convergence_factor that increases the resolution (technically Nx=Ny=Nz) by this factor. To output at twice the resolution, simply run ./wavetoy 2.0, and a new file will be output out0d-conv_factor2.00.txt, which contains data at 2x the resolution.
  4. Analyze the output from out0d-conv_factor1.00.txt and out0d-conv_factor2.00.txt in e.g., gnuplot.
  5. If working with an Einstein Toolkit project, the output will be Einstein Toolkit modules (thorns). You'll want to either copy or link them to an arrangement in arrangements/[subdirectory]/, then add the thorns to your ThornList, and compile.
  6. If working with a superB project, Install Charm++ following the instructions in Charm++ documentation. Then, go to project/superB_two_blackholes_collide and open the Makefile. Replace "~/charm" in CC = ~/charm/bin/charmc with the path to your Charm++ installation directory. Type make to build. Type ./charmrun +p4 ./superB_two_blackholes_collide to run with 4 processors, for example. As in a BlackHoles@Home project parameters can be changed and output from out0d-conv_factor1.00.txt and out0d-conv_factor2.00.txt can be analyzed using e.g., gnuplot.

Contributing to NRPy 2

Want to contribute to NRPy 2? Great! First clone the NRPy 2.0 repo:

git clone https://github.com/nrpy/nrpy.git

Next, you'll want to make sure your development environment is consistent with what GitHub Actions expects:

cd nrpy
pip install -U -r requirements-dev.txt

Finally, to run anything in the NRPy repo, you'll need to set your PYTHONPATH appropriately. If you're using bash, attach the following line to the bottom of your .bashrc file:

export PYTHONPATH=$PYTHONPATH:.

Once this is set up, you can run any Python script in the NRPy 2 repo from the repository's root directory. For example,

python3 nrpy/helpers/cse_preprocess_postprocess.py

will run all the doctests in that file.

Key Improvements over nrpytutorial version of NRPy (NRPy 1):

Easy Installation

  • NRPy has been transformed into a proper Python project and can now be installed via pip! Use the command pip install nrpy to get started.
  • Visit our PyPI page for more information.
    • With pip, it's easier than ever to build your own projects based on NRPy.
    • You can now generate a complete C project from start to finish without the need for running a Jupyter notebook.
      • For instance, running pip install nrpy && python3 -m nrpy.examples.two_blackholes_collide will generate a C code project that evolves Brill-Lindquist forward in time using the BSSN formulation.
    • Check out GitHub README for instructions on generating other pre-baked example codes... or use them to generate your own codes!

Python 3.6+ Features

  • NRPy now makes use of Python features introduced in version 3.6 and above, such as f-strings.
  • The code is now more Pythonic and incorporates objects where useful. Global variables are now a thing of the past!

User-friendly

  • It's much simpler to work with NRPy now; you no longer have to read the source code of each function you call.
    • Facilitating this, you'll find:
      • Docstrings for all functions, classes, and modules.
      • Type hints across all modules; mypy --strict passes.
      • Numerous doctests.
      • Code formatted with Black.
      • Stricter linting.

Improved Continuous Integration

  • GitHub Actions now checks all files within the repo and will fail if any of the following conditions are met:
    • Doctest failure
    • pylint score less than 9.5
    • Black needs to reformat any .py file
    • mypy --strict fails on any .py file
    • Generating and compiling all examples from the pip-installed NRPy fresh from the latest git commit fails.

More Extensible

  • The "SENR" infrastructure has been replaced with "BHaH" (BlackHoles@Home). All BHaH-specific functionality is located in nrpy/infrastructures/BHaH/.
    • While BHaH currently only supports single grids, multi-patch support will be added soon.
    • You'll notice the old paramstruct has been broken into commondata_struct (data shared by all grids) and griddata (contains data specific to a particular grid).
      • Adding multi-patch support is a matter of setting commondata.NUMGRIDS > 1 and all the special algorithms.
    • There is a common but slightly customizable main.c file used by all BHaH codes, see nrpy/infrastructures/BHaH/main_c.py. This should greatly minimize code duplication in BHaH codes.
    • Parameter files are now supported, as well as advanced command-line input.
    • The infrastructures/ directory includes helper functions for specific infrastructures. It currently contains BHaH and CarpetX subdirectories, with more to come.
    • Cparameters has been renamed to CodeParameters, allowing for future extensions of NRPy to output kernels in Python, Fortran, etc.
    • Rewritten expression validation infrastructure, to make it easier to validate newly added sympy expressions -- regardless of how complex they are.

Plans for Old nrpytutorial Code

  • We'll migrate the Jupyter notebooks to a new nrpytutorial GitHub repo as they are updated to NRPy 2.
  • All the core .py files from nrpytutorial have been modernized & ported to NRPy 2.
  • What .py files remain in nrpytutorial will be ported to NRPy 2.

nrpy's People

Contributors

assumpcaothiago avatar leowerneck avatar samuelcupp avatar samueltootle avatar stevenrbrandt avatar zachetienne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nrpy's Issues

Infrastructure-specific GF registration in BSSN functions.

Currently, equations/general_relativity/BSSN_constraints.py has code of the form

if "H" not in gri.glb_gridfcs_dict:
            _ = gri.register_gridfunctions(
                "H", group="AUX", gf_array_name="diagnostic_output_gfs"
            )
            _ = gri.register_gridfunctions(
                "MSQUARED", group="AUX", gf_array_name="diagnostic_output_gfs"
            )
        if register_MU_gridfunctions and "MU" not in gri.glb_gridfcs_dict:
            _ = gri.register_gridfunctions_for_single_rank1(
                "MU", group="AUX", gf_array_name="diagnostic_output_gfs"
            )

The parameter gf_array_name doesn't exist in ETLegacy, so this doesn't work. As a temporary fix, these grid functions can be registered in the infrastructure code so the if always evaluates to false. However, this should be revised so that it works for any infrastructure.

Similarly, equations/general_relativity/BSSN_quantities.py has

if enable_RbarDD_gridfunctions and not any(
            "RbarDD00" in gf.name for gf in gri.glb_gridfcs_dict.values()
        ):
            self.RbarDD = gri.register_gridfunctions_for_single_rank2(
                "RbarDD",
                symmetry="sym01",
                group="AUXEVOL",
                gf_array_name="auxevol_gfs",
            )

with the same problem.

"Make" failed

I use "mingw32-make" to make file in the wavetoy but it fails.
Details are represented below:
系统找不到指定的路径。
cc -O2 -mavx512f -mavx512cd -mavx512vl -mavx512bw -mavx512dq -mavx512ifma -mavx512vbmi -g -Wall -Wno-unused-variable -std=gnu99 -c MoL_free_memory_non_y_n_gfs.c -o MoL_free_memory_non_y_n_gfs.o
process_begin: CreateProcess(NULL, cc -O2 -mavx512f -mavx512cd -mavx512vl -mavx512bw -mavx512dq -mavx512ifma -mavx512vbmi -g -Wall -Wno-unused-variable -std=gnu99 -c MoL_free_memory_non_y_n_gfs.c -o MoL_free_memory_non_y_n_gfs.o, ...) failed.
make (e=2):
Makefile:23: recipe for target 'MoL_free_memory_non_y_n_gfs.o' failed
mingw32-make: *** [MoL_free_memory_non_y_n_gfs.o] Error 2

An error appears when I input "python3 -m nrpy.examples.wave_equation_cartesian".

When I have downloaded nrpy through pip in cmd, then an error happens after I input "python -m nrpy.examples.wave_equation_cartesian".

Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "D:\Anaconda3_2309\Lib\site-packages\nrpy\examples\wave_equation_cartesian.py", line 438, in
register_CFunction_exact_solution_single_Cartesian_point()
File "D:\Anaconda3_2309\Lib\site-packages\nrpy\examples\wave_equation_cartesian.py", line 187, in register_CFunction_exact_solution_single_Cartesian_point
cfc.register_CFunction(
File "D:\Anaconda3_2309\Lib\site-packages\nrpy\c_function.py", line 274, in register_CFunction
CFunction_dict[actual_name] = CFunction(
^^^^^^^^^^
File "D:\Anaconda3_2309\Lib\site-packages\nrpy\c_function.py", line 101, in init
self.raw_function, self.full_function = self.generate_full_function()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Anaconda3_2309\Lib\site-packages\nrpy\c_function.py", line 198, in generate_full_function
return complete_func, clang_format(
^^^^^^^^^^^^^
File "D:\Anaconda3_2309\Lib\site-packages\nrpy\helpers\generic.py", line 80, in clang_format
with subprocess.Popen(
^^^^^^^^^^^^^^^^^
File "D:\Anaconda3_2309\Lib\subprocess.py", line 1026, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\Anaconda3_2309\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

An error appears when I input "python -m nrpy.examples.two_blackholes_collide"

Setting up reference metric for CoordSystem = Spherical.
Setting up reference metric for CoordSystem = Spherical.
Traceback (most recent call last):
File "", line 1, in
File "D:\Anaconda3_2309\Lib\site-packages\multiprocess\spawn.py", line 120, in spawn_main
exitcode = _main(fd, parent_sentinel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Anaconda3_2309\Lib\site-packages\multiprocess\spawn.py", line 129, in _main
prepare(preparation_data)
File "D:\Anaconda3_2309\Lib\site-packages\multiprocess\spawn.py", line 238, in prepare
_fixup_main_from_name(data['init_main_from_name'])
File "D:\Anaconda3_2309\Lib\site-packages\multiprocess\spawn.py", line 262, in _fixup_main_from_name
main_content = runpy.run_module(mod_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 226, in run_module
File "", line 98, in _run_module_code
File "", line 88, in _run_code
File "D:\Anaconda3_2309\Lib\site-packages\nrpy\examples\two_blackholes_collide.py", line 194, in
par.adjust_CodeParam_default("eta", GammaDriving_eta)
File "D:\Anaconda3_2309\Lib\site-packages\nrpy\params.py", line 373, in adjust_CodeParam_default
raise ValueError(
ValueError: Cannot adjust "eta" default value, as it does not appear in glb_code_params_dict

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.