NuCon is a Python library designed to interface with and control parameters in [Nucleares](https://store.steampowered.com/app/1428420/Nucleares/), a nuclear reactor simulation game. It provides a robust, type-safe foundation for reading and writing game parameters, allowing users to easily create their own automations and control systems.
NuCon further provides a work in progress implementation of a reinforcement learning environment for training control policies and a simulator based on model learning.
-`nucon.<PARAMETER>.read()`: Get the current value of the parameter (alias for `value`)
-`nucon.<PARAMETER>.write(new_value, force=False)`: Write a new value to the parameter. `force` will try to write even if the parameter is known as non-writable or out of known allowed range.
-`nucon.get(parameter)`: Get the value of a specific parameter. Also accepts string parameter names.
-`nucon.set(parameter, value, force=False)`: Set the value of a specific parameter. Also accepts string parameter names. `force` will try to write even if the parameter is known as non-writable or out of known allowed range.
-`nucon.get_all_readable()`: Get a list of all readable parameters (which is all parameters)
-`nucon.get_all_writable()`: Get a list of all writable parameters
-`nucon.get_all()`: Get all parameter values as a dictionary
-`nucon.get_multiple(params)`: Get values for multiple specified parameters
-`nucon.set_dummy_mode(dummy_mode)`: Enable or disable dummy mode for testing
So if you're not in the mood to play the game manually, this API can be used to easily create your own automations and control systems. Maybe a little PID controller for the rods? Or, if you wanna go crazy, why not try some
NuCon includes a preliminary Reinforcement Learning (RL) environment based on the OpenAI Gym interface. This allows you to train control policies for the Nucleares game instead of writing them yourself. This feature is currently a work in progress and requires additional dependencies.
The `NuconEnv` class in `nucon/rl.py` provides a Gym-compatible environment for reinforcement learning tasks in the Nucleares simulation. Key features include:
Objectives takes either strings of the name of predefined objectives, or lambda functions which take an observation and return a scalar reward. Final rewards are (weighted) summed across all objectives. `info['objectives']` contains all objectives and their values.
But theres a problem: RL algorithms require a huge amount of training steps to get passable policies, and Nucleares is a very slow simulation and can not be trivially parallelized. That's why NuCon also provides a
## Simulator (Work in Progress)
NuCon provides a built-in simulator to address the challenge of slow training times in the actual Nucleares game. This simulator allows for rapid prototyping and testing of control policies without the need for the full game environment. Key features include:
- Mimics the behavior of the Nucleares game API
- Configurable initial states and operating modes
- Faster than real-time simulation
- Supports parallel execution for increased training throughput
### Additional Dependencies
To use you'll need to install the following packages:
from nucon.sim import NuconSimulator, OperatingState
# Create a simulator instance
simulator = NuconSimulator()
# Load a dynamics model (explained later)
simulator.load_model('path/to/model.pth')
# Set initial state (optional)
simulator.set_state(OperatingState.NOMINAL)
# Run the simulator, will start the web server
simulator.run()
# Access via nucon by using the simulator's port
nucon = Nucon(port=simulator.port)
# Or use the simulator with NuconEnv
from nucon.rl import NuconEnv
env = NuconEnv(simulator=simulator) # When given a similator, instead of waiting on the game, we will tell the simulator to skip forward after each step
# Train your RL agent using the simulator
# ...
```
But theres yet another problem: We do not know the exact simulation dynamics of the game and can therefore not implement an accurate simulator. Thats why NuCon also provides
## Model Learning (Work in Progress)
To address the challenge of unknown game dynamics, NuCon provides tools for collecting data, creating datasets, and training models to learn the reactor dynamics. This approach allows for more accurate simulations and enables model-based control strategies. Key features include:
- Data Collection: Supports gathering state transitions from both human play and automated agents.
- Dataset Management: Tools for saving, loading, and merging datasets.
- Model Training: Train neural network models to predict next states based on current states and time deltas.
- Dataset Refinement: Ability to refine datasets by focusing on more challenging or interesting data points.
NuCon is an unofficial tool and is not affiliated with or endorsed by the creators of Nucleares.
## Citing
What? Why would you wanna cite it? What are you even doing?
```
@misc{nucon,
title = {NuCon},
author = {Dominik Roth},
abstract = {NuCon is a Python library to interface with and control Nucleares, a nuclear reactor simulation game. Includes gymnasium bindings for Reinforcement Learning.},