A package for simulating cres experiments over a variety of magnetic field values.
Get dependencies:
cd /data/eliza4/he6_cres/simulation/
pip3 install -r he6-cres-spec-sims/requirements.txt --user
pip3 install --upgrade pip
module load python-3.7.3
to your enviornment setup file or .bash_profile file so that you have access to python3.Simulate an experiment:
cd /data/eliza4/he6_cres/simulation/he6-cres-spec-sims
.json
experiment config and a .yaml
base config to both be in the following directory on rocks: /data/eliza4/he6_cres/simulation/sim_results/experiments/
. (TODO: Document the config files and the output fields.)he6-cres-spec-sims/config_files
). You should be able to do the same with minimal adjustment of paths.
!scp /home/drew/He6CRES/he6-cres-spec-sims/config_files/rocks* drewbyron@172.25.100.1:/data/eliza4/he6_cres/simulation/sim_results/experiments
./he6_cres_spec_sims/run_rocks_experiment.py -exp "/data/eliza4/he6_cres/simulation/sim_results/experiments/rocks_exp_config_example.json"
./he6_cres_spec_sims/run_rocks_experiment.py -exp "/data/eliza4/he6_cres/simulation/sim_results/experiments/rocks_exp_config_example.json" -clean True
-exp
(str): Specify the path to the json file that contains the specific attributes (in the form of a python dictionary) of the simulated experiment. See the docstring for the run_rocks_experiment.py
module for a complete description of all attributes that the .json
must contain..json
experiment config locally based on some queries to the he6 postgreSQL database. You could copy that to the rocks sim_results/experiments
directory with a command like this:
!scp /media/drew/T7\ Shield/spec_sims_results/rocks_experiments/exp_demo_nov2022.json drewbyron@172.25.100.1:/data/eliza4/he6_cres/simulation/sim_results/experiments
experiment_copies
number of independent (unique random seeds) but otherwise identical experiments are run over rocks. The experiment attribute experiment_copies
is specified in the .json
config file. It is parallelized such that each field specified in each copy is sent to a different node. So for example if the .json
config had these attributes: {"experiment_copies": 5, "beta_num": 1000, "fields_T": [1.0, 2.0, 3.0]}
, then 5 copies x 3 fields = 15 nodes would each simulate 1000 betas. .csvs
containing track info for the 5 copies is combined into one directory. .txt
files. Occassionally just delete the contents of simulation/sim_logs
.SimulationResults
from the results.py
module (need to have a local copy of the repo) to grab the experiment results. sys.path.append("/home/drew/He6CRES/he6-cres-spec-sims/")
(enables you to run this anywhere, change paths to be your own)from he6_cres_spec_sims.results import SimulationResults
local_dir = "/media/drew/T7 Shield/spec_sims_results/rocks_experiments"
sim_exp_name = "rocks_exp_config_example"
sim = SimulationResults(local_dir = local_dir, sim_exp_name = sim_exp_name )
sim
instance contains: sim.results.__dict__
sim.results.tracks
he6-cres-spec-sims/demo/rocks_sim_experiment_demo.ipynb
.Install:
git pull
if you already have it. A hard reset to the remote may be necessary if you have an old version. You should be on the develop
branch (default).
git clone git@github.com:Helium6CRES/he6-cres-spec-sims.git
pip install .
Simulate an experiment:
Instructions:
he6-cres-spec-sims
parent directory..json
experiment config and a .yaml
base config to both be in a directory suited for simulation results. For me this is in an external drive. he6-cres-spec-sims/config_files
). You should be able to do the same with minimal adjustment of paths.
cp /home/drew/He6CRES/he6-cres-spec-sims/config_files/local* /media/drew/T7\ Shield/spec_sims_results/local_experiments
base_config_path
field in the .json
experiment config needs to be manually changed to point at the .yaml
base config file. Change this path. Run experiment:
./run_local_experiment.py -exp "/media/drew/T7 Shield/spec_sims_results/local_experiments/local_exp_config_example.json"
Interactive Python
import he6_cres_spec_sims
he6_cres_spec_sims.run_local_experiment("/media/drew/T7 Shield/spec_sims_results/local_experiments/local_exp_config_example.json")
Notes:
experiment_copies
field in the local .json
config. The base config (.yaml
) is identical. Analyzing simulation results:
ExperimentResults
from the experiment.py
module to grab the experiment results. sys.path.append("/home/drew/He6CRES/he6-cres-spec-sims/")
(enables you to run this anywhere, change paths to be your own)from he6_cres_spec_sims.experiment import ExpResults
experiment_config_path = "/media/drew/T7 Shield/spec_sims_results/local_experiments/local_exp_config_example/local_exp_config_example_exp.yaml"
sim = ExpResults.load(experiment_config_path =experiment_config_path )
sim
instance contains: sim.__dict__
sim.tracks
he6-cres-spec-sims/demo/local_sim_experiment_demo.ipynb
.The most basic function of the simulation package is to simulate betas in a given trap depth and main field. An "experiment" is a set of individual simulations run together with organized output. This makes it easy to simulate something closely resembling our experiments; running at a range of trap depths and main field values. The .json
experiment config serves as the instructions for which simulations to run in the experiment.
One can find an example of this config file here: /he6-cres-spec-sims/config_files/rocks_exp_config_example.json
. Note that the name the experiment directory is assigned is the name of the .json
experiment config file.
{
"experiment_copies": 3,
"base_config_path": "/data/eliza4/he6_cres/simulation/sim_results/experiments/rocks_base_config_example.yaml",
"isotope": "He6",
"events_to_simulate": -1,
"betas_to_simulate": 1e2,
"rand_seeds": [4062, 3759, 3456, 3153, 2850, 2547, 2244, 1941, 1638, 1335, 1032],
"fields_T": [3.25, 3.0, 2.75, 2.5, 2.25, 2.0, 1.75, 1.5, 1.25, 1.0, 0.75],
"traps_A": [1.8, 1.661538, 1.523077, 1.384615, 1.246154, 1.107692, 0.969231, 0.830769, 0.692308, 0.553846, 0.4153845]
}
experiment_copies:
.json
config had these attributes: {"experiment_copies": 5, "beta_num": 1000, "fields_T": [1.0, 2.0, 3.0]}
, then 5 copies x 3 fields = 15 nodes would each simulate 1000 betas. Then the clean-up phase would combine these all into a directory whose name matches the .json
config name. base_config_path:
isotope:
events_to_simulate:
betas_to_simulate:
rand_seeds:
fields_T:
traps_A:
.json
config:my_exp_dict
that contains all required fields.import json
json.dump(my_exp_dict, 'path_to_exp_dict.json')
The base configuration .yaml
file contains the specific parameters to use for each "block" of an individual simulation. When running an experiment, certain settings are over-written (like the betas_to_simulate
) by the .json
experiment config. But the general settings defined in the .yaml
base config are used across all fields and trap depths defined in the .json
experiment config.
One can find an example of this config file here: /he6-cres-spec-sims/config_files/rocks_base_config_example.yaml
Below is a description for all of the features output by the simulations. One can find instructions for generating the tracks
pd.Dataframe above for a local or cluster based simulation.
[
'energy':
'gamma',
'energy_stop',
'initial_rho_pos',
'initial_phi_pos',
'initial_zpos',
'initial_theta',
'cos_initial_theta',
'initial_phi_dir',
'center_theta',
'cos_center_theta',
'initial_field',
'initial_radius',
'center_x',
'center_y',
'rho_center',
'trapped_initial_theta',
'max_radius',
'min_radius',
'avg_cycl_freq',
'b_avg',
'freq_stop',
'zmax',
'axial_freq',
'mod_index',
'segment_power',
'slope',
'segment_length',
'band_power',
'band_num',
'segment_num',
'event_num',
'beta_num',
'fraction_of_spectrum',
'energy_accept_high',
'energy_accept_low',
'gamma_accept_high',
'gamma_accept_low',
'time_start',
'time_stop',
'freq_start',
'exp_copy',
'simulation_num',
'field',
'trap_current']
develop
branch is tested and working on rocks and locally as of 11/16/22.