SimLogger.SimLogger module
The SimLogger module is the fundamental piece of the SimLogger package.
The SimLogger functions on the key principal that everything in a simulation can be uniquely identified with the following: 1. simTag - uniquely identifies a particular simulation configuration.
This is changed for every single test run. Everytime the parameters are changed (and you re-run your simulation) you should update your simTag accordingly.
- objTag - uniquely identifies a particular object within a simulation.
This is the same across simulations, but should be a unique name for the object within the simulation.
- date-time string - all pickled files have an additional date-time string
appended to the file name to avoid any accidental overwriting of data.
With that, all data can be uniquely named and pickled to file. Pickling provides an easy way to store and load files in python, and is the compression method used in the SimLogger.
This could be an example script
Which lays out the simTag for the simualtion, then defines an object we are going to save, with the objTag and then stores it with the SimLogger. This also generates an example.log file so that you can always refer somewhere to know exactly where the data has been stored.
In future analysis, the data can be loaded as needed using the following To reference the object you will need the unique id of the object, which is simTag_objTag
Within this framework, various configurations can be changed: - log file name - folder where the pickled files get saved
SimLogger.SimLogger Functions
- SimLogger.SimLogger.convertLog(logfile='example.log', logdir='.')[source]
Convert a log to a csv format based on the simulation input/outputs
- Parameters:
logfile (str) – the log file name
logdir (str) – directory where the file is located
- Returns:
None
- SimLogger.SimLogger.getObjectFromUniqueId(uniqueId, objFolder='data/obj')[source]
Loads an object previously saved from the unique id ({simTag}_{objTag})
- Parameters:
uniqueId (str) – Unique id of the pickled file name ({simTag}_{objTag})
objFolder (str) – Folder containing the pickled files
- Returns:
Loaded pickled object
- Return type:
obj (Object)
- SimLogger.SimLogger.isSimTagUsed(simTag, objFolder='data/obj')[source]
Checks if there are any objects already saved in the objFolder that uses the simTag
- Parameters:
simTag (str) – Unique simulation id
objFolder (str) – Folder containing the pickled files
- Returns:
whether there are pkl files with the simTag used
- Return type:
isUsed (bool)
- SimLogger.SimLogger.logNotes(notes)[source]
Save a notes string to the log directly
- Parameters:
notes (str) – text that will be written to the log
- Returns:
None
- SimLogger.SimLogger.saveObj(simTag, objTag, obj, objFolder='data/obj', makeNote=False)[source]
Save an object (obj) to pickle file in the object folder. The file name will be the {simTag}_{objTag}_{dateTimeString}.pkl
- Parameters:
simTag (str) – Unique tag for the simulation
objTag (str) – Unique tag for the object within the simulation
obj (Object) – Object to be pickled and saved to file
objFolder (str) – Folder where the pickled file will be saved
makeNote (bool) – Sets whether an additional note is made about the object
- Returns:
the unique file path where the pickled object is saved
- Return type:
filePath (str)
- SimLogger.SimLogger.saveSimulation(simTag, inputDict, outputDict, notes='No additional notes')[source]
Save inputs and outputs of a simulation
- Parameters:
simTag (str) – Unique tag for the simulation
({str (outputDict) – Object}): list of object names (keys) and the objects to be saved (values)
({str – Object}): same structure as the inputDict
notes (str) – Additional notes to be written at the end of the log
- Returns:
None
- SimLogger.SimLogger.setupLogger(fileName='example.log', githubLink=None)[source]
Initialize the logger. Sets the log directory and the default object directoy.
- Parameters:
fileName (str) – file name for the log output
githubLink (str) – link to the github repository to allow for the note of the most recent commit to be in the form of a github link directly to that commit ex. “www.github.com/joey-kilgore/SimLogger”
- Returns:
None