Skip to content

Add fully automatic argparse argument saving with ArgumentParser - #36

Draft
joey-kilgore with Copilot wants to merge 3 commits into
mainfrom
copilot/add-autosave-command-line-args
Draft

joey-kilgore with Copilot wants to merge 3 commits into
mainfrom
copilot/add-autosave-command-line-args

Conversation

Copilot AI commented Nov 20, 2025

Copy link
Copy Markdown

Users frequently forget to save command-line arguments when using argparse, making it difficult to reproduce scientific experiments.

Changes

  • New SimLogger.ArgumentParser class - Custom ArgumentParser that automatically saves arguments when parse_args() is called (fully automatic!)
  • setSimTag() function - Sets global simulation tag for automatic saving
  • saveArgs() function - Manual saving option that accepts simTag and argparse Namespace, converts to dict, persists via pickle, and logs each argument individually
  • Tests - Comprehensive coverage for automatic and manual saving scenarios (6 tests total)
  • Documentation - Usage examples in README for both automatic and manual approaches

Usage

Fully Automatic (Recommended)

from SimLogger import SimLogger

# Set tag once
SimLogger.setSimTag('experiment_v1')

# Use SimLogger.ArgumentParser instead of argparse.ArgumentParser
parser = SimLogger.ArgumentParser()
parser.add_argument('--learning_rate', type=float, default=0.001)
parser.add_argument('--epochs', type=int, default=100)

# Arguments are AUTOMATICALLY saved when parse_args() is called!
args = parser.parse_args()

Alternatively, pass simTag directly to the parser:

parser = SimLogger.ArgumentParser(simTag='experiment_v1')
args = parser.parse_args()  # Automatically saved!

Manual Saving

import argparse
from SimLogger import SimLogger

parser = argparse.ArgumentParser()
parser.add_argument('--learning_rate', type=float, default=0.001)
args = parser.parse_args()

# Manually save all arguments
SimLogger.saveArgs('experiment_v1', args)

Loading Saved Arguments

# Later: retrieve as dict
loaded = SimLogger.getObj('experiment_v1', 'args')

Arguments are logged individually:

[INFO] ARGS,experiment_v1,saved,data/obj/experiment_v1_args_2024-11-20_18-15-30.pkl
[INFO] ARG,experiment_v1,learning_rate,0.001
[INFO] ARG,experiment_v1,epochs,100
Original prompt

This section details on the original issue you should resolve

<issue_title>Autosave command line args</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
I always forget to save the CLI args when using argparse. Please do it automatically.

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…rguments

Co-authored-by: joey-kilgore <22432499+joey-kilgore@users.noreply.github.com>
Copilot AI changed the title [WIP] Add autosave for command line arguments in argparse Add saveArgs() to automatically persist argparse CLI arguments Nov 20, 2025
Copilot AI requested a review from joey-kilgore November 20, 2025 18:17
@joey-kilgore

Copy link
Copy Markdown
Owner

@copilot The hope was to do this automatically so that when we call parser.parse_args() to automatically save that args to file? is there a way to handle this?

Co-authored-by: joey-kilgore <22432499+joey-kilgore@users.noreply.github.com>

Copilot AI commented Nov 21, 2025

Copy link
Copy Markdown
Author

@copilot The hope was to do this automatically so that when we call parser.parse_args() to automatically save that args to file? is there a way to handle this?

Yes! I've implemented fully automatic saving. Now you can use SimLogger.ArgumentParser instead of argparse.ArgumentParser and arguments are automatically saved when you call parse_args().

Two ways to use it:

Option 1 - Set simTag globally:

from SimLogger import SimLogger

SimLogger.setSimTag('myExperiment')
parser = SimLogger.ArgumentParser()
parser.add_argument('--learning_rate', type=float, default=0.001)
args = parser.parse_args()  # Automatically saved!

Option 2 - Pass simTag to parser:

parser = SimLogger.ArgumentParser(simTag='myExperiment')
args = parser.parse_args()  # Automatically saved!

No need to call saveArgs() manually anymore - it just works when you call parse_args().

Implemented in commit cb97827.

Copilot AI changed the title Add saveArgs() to automatically persist argparse CLI arguments Add fully automatic argparse argument saving with ArgumentParser Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autosave command line args

2 participants