Package: phantomconfig
Phantom configphantom-config: parse, convert, modify, and generate Phantom config filesphantom-config can readPhantom.inand.setupfiles. (They have the same format.) You can, for example:modify config values or comment strings,add new variables or delete old ones,write the config to a JSON or TOML file,generate a config file from a Python dictionary.InstallationInstall phantom-config with pippython-mpipinstallphantomconfigRequirementsPython 3.7+ only. Optionallytomlkitfor read/write to TOML format.UsageBasic usageImport phantom-config.>>>importphantomconfigTo read in a Phantom config file>>>input_file=phantomconfig.read_config('prefix.in')Print a summary>>>input_file.summary()The variables, with their values, comment string, and the block they are a member of, are stored in a dictionary accessed by the.configmethod.>>>dtmax=input_file.config['dtmax']The keys of this dictionary correspond to the variable name, and values are aConfigVariablenamed tuple with the variable name, value, comment, and block.>>>dtmax.name>>>dtmax.value>>>dtmax.comment>>>dtmax.blockYou can just get the value if you want.input_file.get_value('dtmax')If you like, you can write the Phantom config as a JSON file, and you can read the JSON file.>>>input_file.write_json('prefix-in.json')>>>json_file=phantomconfig.read_json('prefix-in.json')Check that the configs are equal>>>input_file.config==json_file.configYou can also read and write TOML files.>>>input_file.write_toml('prefix-in.toml')>>>toml_file=phantomconfig.read_toml('prefix-in.toml')You can add a new variable, remove a variable, and change the value of a variable.# Add new variable>>>input_file.add_variable(...'new_var',...12345678,...comment='Sets thing',...block='options controlling things',...)# Remove a variable>>>input_file.remove_variable('dtmax')# Change the value of a variable>>>input_file.change_value('dumpfile','new_dumpfile_name')Then you can write the Phantom config file with the modified values.>>>input_file.write_phantom('new.in')ExamplesGenerate a config from a dictionaryYou can create a Phantom.setupfile from a Python dictionary. First create the dictionary>>>setup=dict()>>>setup['gas properties']={...'cs':(cs,'sound speed'),...'npart':(npart,'number of particles in x direction'),...'rhozero':(rhozero,'initial density'),...'ilattice':(ilattice,'lattice type'),...}Then you can read the dictionary withphantomconfig, and write to a Phantom.setupfile>>>setup_config=phantomconfig.read_dict(setup)>>>setup_config.header=[...'input file for some particular setup routine',...'short description of what it does',...]>>>setup_config.write_phantom('filename.setup')This writes a file like# input file for some particular setup routine
# short description of what it does

# gas properties
                  cs =        1.000   ! sound speed
               npart =         9999   ! number of particles in x direction
             rhozero =        0.100   ! initial density
            ilattice =            2   ! lattice typeWriting multiple configsSay you want to write multiple configs, each with a different parameter value. For example, you have a template.infile and you want to vary the alpha parameter. The followingreads the template fileloops over a list ofalphavalues, writing a new.infile for each value in the listalphas=[0.1,0.2,0.3]infile=phantomconfig.read_config('template.in')foralphainalphas:infile.change_value('alpha',alpha)infile.write_phantom(f'alpha={alpha}.in')See alsophantom-buildphantom-buildis a Python package designed to make it easy to generate reproducible Phantom builds for writing reproducible papers. You can generate.inand.setupfiles with phantom-config and then, with phantom-build, you can compile Phantom and set up multiple runs, and schedule them via, for example, the Slurm job scheduler.phantom-setupphantom-setupis a (work in progress) Python package designed to set up Phantom initial conditions in pure Python, i.e. with no Fortran dependencies. It uses NumPy and Numba to achieve Fortran like performance for computationally expensive operations.