Code Monkey home page Code Monkey logo

plasmaevolution's Introduction

This repo trains and analyzes neural nets for predicting how a tokamak (fusion reactor) plasma will evolve in time given an initial condition and user-specified actuator trajectories. It is a (pytorch-based) cleanup of the (tensorflow-based) plasma-profile-predictor, which was described in our 2021 Nuclear Fusion paper.

Generate an h5 file with data-fetching repo

-------- TO TRAIN A MODEL --------- In configs/default.cfg point raw_data_filename to the generated h5 file. Then change preprocessed_data_filename_base to a "base" name for writing processed data. Run preprocess_data.py, which will generate the basename with _train.pkl, _val.pkl, and _test.pkl appended. Change output_dir in the config file to where you want to dump a model, then run python ian_train.py to train a model to go there. To train a full ensemble of models (submitting them to slurm on traverse) do python launch_ensemble.py which will train 10 with 0,...,9 appended to the end. Use modelStats.py {config_filename} to plot training losses.

-------- TO CREATE AND VISUALIZE MODEL OUTPUTS --------- Run SimpleModelRollout.py {config_filename} (where config_filename is the full path to the config file corresponding to the model) to create a pickle file with the predicted profiles. Set plot_ensemble to True or False depending on whether you're doing ensemble modeling or one model at a time. To visualize the predictions, use prediction_plotter.ipynb

-------- TO HELP TEST --------- Set train_shots, val_shots, and test_shots to a small number of shots each

-------- TO TUNE MODELS ------- Training takes a long time with curriculum learning. If you have a good model with the right inputs and want to tune it on simulation or other-machine data, or overfit it to data (e.g. for developing control for a specific scenario), copy the config file from the model you like, then

  1. set tune_model to true
  2. set the model_to_tune_filename_base to the output_filename_base (i.e. you're tuning the good model)
  3. set the output_filename_base to your new model name If you only want to tune certain layers add the layer names as a list. In torch layer names correspond to named class variables (self.rnn --> rnn, self.encoder --> encoder, self.decoder --> decoder) and can be found with for name, child in model.named_children(): print(name)
  4. for most cases set autoregression_start_epoch and autoregression_end_epoch to 0 since you don't want to go back to the beginning of the curriculum learning, you want to start from what you already have
  5. for some cases (e.g. for training on simulations where you only confidently can predict out to rho=0.8 and you only predict a subset of the profiles like TE and TI) add a list of the profiles you don't want to consider to masked_outputs and set tuning-->rho_bdry_index to the index of the boundary (e.g. rho=0.8 for nx=33 would be 0.8*33 ~ 26). This will mask those outputs during training.

-------- LRAN TRAINING AND CONTROL --------- To train a model with latent linear dynamics (LRAN) to be used to control applications, change the model.cfg model_type from IanRNN to HiroLRAN and repeat training steps above. To launch a control simulation, where the controller makes MPC actuator decisions using HiroLRAN and the profile evolution is simulated using IanRNN, use control_simulation.py. To visualize these results use control_plotter.ipynb.

-------- ENVIRONMENT SETUP --------- For pytorch environment setup on PPPL/Princeton's Traverse cluster along with a ton of other helpful info and examples, see researchcomputing.princeton.edu. h5py is also required for reading the h5 dataset. As of February 2023, I personally use module load anaconda3/2022.5 conda create --name torch --channel "https://opence.mit.edu/#/" "pytorch==1.12*=cuda11*" torchvision conda install -c anaconda h5py conda activate torch

And of course reload anaconda and activate this environment every time you go to run the code.

plasmaevolution's People

Contributors

jabbate7 avatar hirofarre avatar

Stargazers

Saif Khayoon avatar Richard Kraaijenhagen avatar  avatar Adam Kit avatar

Watchers

Azarakhsh avatar  avatar Dario Panici avatar

Forkers

mit-psfc

plasmaevolution's Issues

Add dropout to train big model w/ all signals

Also 0 out signals that are missing rather than excluding them completely - ideally make model that can take as many inputs as possible (but knows how to deal with 0 values for rotation / Ti / etc. if they're missing)

Make causality testing script

Make a few fake shots and overlap original prediction with perturbed prediction to see effect. Plot average profile vs actuator (eg Ti vs Pinj).

Rotation seems to flip sign

From Hiro:

170592 is completely wrong (negative all the way with autoregression, huge error bar without autoregression). 176462 is right but around the end of the shot, the non autoregressive model flips. Might be a sign error in some of the data.

Model without autoregression during training:
image

Model with autoregression during training:
image

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.