Skip to content

Repository files navigation

/* © 2026. Triad National Security, LLC. All rights reserved.

This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S. Department of Energy/National Nuclear Security Administration. All rights in the program are reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear Security Administration. The Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare. derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so.

(End of Notice) */

ReLearnDecomp

This project contains the framework for reinforcement learning of decomposition of a composite shape into primary shapes.

TO GET STARTED WITH TESTING THE RL FUNCTIONALITY HERE, DO THIS:

brew install conda    # install Anaconda3
conda activate        # activate conda (makes available python, jupyter-notebooks etc)
pip install gym      # install OpenAI Gym
brew install cmake openmpi       # needed for stable-baselinesmpi ???? Do we need
pip install stable-baselines3

Install PythonOCC-core, a Python interface to the OpenCascade geometric modeler

conda create --name=pyoccenv python=<python version>  # 3.8 for me
source activate pyoccenv
conda install -c conda-forge pythonocc-core=7.5.1 occt=7.5.1  # PythonOCC-core

Now you can run

conda activate pyocc
python decompEnvCheck.py

Darwin Installation

module load miniconda3/py311_23.11.0
module load cuda/11.8
conda create --name=pyoccenv python=3.11 matplotlib
source activate pyoccenv  # Darwin recommends this
conda install -c conda-forge mamba
mamba install pytorch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 pytorch-cuda=11.8 pyg pytorch-spline-conv -c pytorch -c nvidia -c pyg
mamba install -c conda-forge pythonocc-core=7.8.1 meshpy
pip install steputils gym pyglet

NOTE: Make sure any paths that a previous conda init may have written into the .bashrc or .cshrc point to the right python. If not, rerun conda init

Usage

To run the RL code in Darwin:

  • Configure run script main_all.py via command line options
  • Allocate resource, launch environment and run main script

Example scripts for submitting jobs to Darwin queue are included next. Set the paths for training and testing data in the provided scripts according to your local configuration.

DQN Cutter

#!/bin/bash
#SBATCH -N1 --qos=long --time=24:00:00 -p volta-x86
module load miniconda3
module load cuda/11.8
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
conda activate pyoccenv
python -u main_all.py --model_type dqn_cut --out_path ./out_dqn_cut/ --checkpoint_dir ./out_dqn_cut/models/ --training_data_path ~/hexml/data/Training/ --test_data_path ~/hexml/data/Test/ > log_dqncut_planar_rect_data.txt
conda deactivate

DQN Splitter

#!/bin/bash
#SBATCH -N1 --qos=long --time=24:00:00 -p volta-x86
module load miniconda3
module load cuda/11.8
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
conda activate pyoccenv
python -u main_all.py --model_type dqn_split --out_path ./out_dqn_split/ --checkpoint_dir ./out_dqn_split/models/ --training_data_path ~/hexml/data/Training/ --test_data_path ~/hexml/data/Test/ > log_dqnsplit_planar_rect_data.txt
conda deactivate

SAC Cutter

#!/bin/bash
#SBATCH -N1 --qos=long --time=24:00:00 -p volta-x86
module load miniconda3
module load cuda/11.8
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
conda activate pyoccenv
python -u main_all.py --model_type sac_cut --out_path ./out_sac_cut/ --checkpoint_dir ./out_sac_cut/models/ --training_data_path ~/hexml/data/Training/ --test_data_path ~/hexml/data/Test/ --actor_lr 0.0003 --critic_lr 0.0003 > log_saccut_planar_rect_data.txt
conda deactivate

SAC Splitter

#!/bin/bash
#SBATCH -N1 --qos=long --time=24:00:00 -p volta-x86
module load miniconda3
module load cuda/11.8
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
conda activate pyoccenv
python -u main_all.py --model_type sac_split --training_data_path ~/hexml/data/Training/ --test_data_path ~/hexml/data/Test/ > log_sacsplit_planar_rect_data.txt
conda deactivate

SAC Splitter Edge-Based Cuts

#!/bin/bash
#SBATCH -N1 --qos=long --time=24:00:00 -p volta-x86
module load miniconda3
module load cuda/11.8
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
conda activate pyoccenv
python -u main_all.py --model_type sac_split --cut_type 2 --out_path ./out_edge/ --checkpoint_dir ./out_edge/models/ --training_data_path ~/hexml/data_rotated/Training/ --test_data_path ~/hexml/data_rotated/Test/ > log_sacsplit_rect_rotated_data.txt
conda deactivate

Evaluation

To evaulate trained RL models in Darwin:

  • Configure run script eval_model.py via command line options
  • Allocate resource, launch environment and run main script

An example command for running the evaluation script is included next. Set the paths for testing data and trained model according to your local configuration.

python -u eval_model.py --model_type sac_split --cut_type 2 --checkpoint_dir ./out_edge/models --test_data_path ~/hexml/data_rotated/Test --out_path ./out_edge/eval --render_decomps True > log_evaluation.txt

Authors and acknowledgment

Contributors: HexML group.

About

Experimental code to decompose planar CAD shapes using reinforcement learning

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages