Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/286 sysmodel logger #287

Merged
merged 11 commits into from
Sep 15, 2023
Merged

Feature/286 sysmodel logger #287

merged 11 commits into from
Sep 15, 2023

Conversation

juan-g-bonilla
Copy link
Contributor

@juan-g-bonilla juan-g-bonilla commented Apr 9, 2023

Description

Variable logging was implemented through a SysModel, which is added to a task similarly to message recorders. For usage, see documentation bskPrinciples 6.

The new SysModel logger take arbitrary lambdas as callback functions for logging, which are given in a dictionary. However, for recording simple module attributes, the utility function logger has been added to every module, which takes as input a string or list of strings and produces a logger that will record the given attributes:

moduleLogger = module.logger(["dummy", "dumVector"], macros.sec2nano(1.))
scSim.AddModelToTask("dynamicsTask", moduleLogger)

is equivalent to:

moduleLogger = pythonVariableLogger.PythonVariableLogger(
        {
            "dummy": lambda _: module.dummy,
            "dumVector": lambda _: module.dumVector,
        }, 
        macros.sec2nano(1.)
    )
scSim.AddModelToTask("dynamicsTask", moduleLogger)

The logger method is added to SysModel through a new swig file that all module swig files now include. An error is raised for scripts that try to access logger for modules that do not use the swig file (i.e. they use %include sys_model.h instead of %include sys_model.i).

The following methods are now deprecated:

  • AddVariableForLogging
  • GetLogVariableData
  • RecordLogVars

However, they still work as expected. This was accomplished by having these functions call the new logging functionality internally, which means that the old logging has been completely removed from the code.

Verification

All scenarios and tests that used the old syntax have been updated to the new syntax, and all are passing. On a personal note, updating these has been a pain as it is difficult to script the conversion reliably.

Documentation

bskPrinciples-6 was updated to reflect the new way of logging variables. Note that the associated video is now outdated. Scenarios have also been updated to use the new syntax.

@juan-g-bonilla juan-g-bonilla added the enhancement New feature or request label Apr 9, 2023
@juan-g-bonilla juan-g-bonilla self-assigned this Apr 9, 2023
src/utilities/variable_logger.py Outdated Show resolved Hide resolved
src/utilities/variable_logger.py Outdated Show resolved Hide resolved
src/utilities/variable_logger.py Outdated Show resolved Hide resolved
@juan-g-bonilla
Copy link
Contributor Author

Some test errors are due to #288. Therefore, this PR is dependant on a fix to #288.

@juan-g-bonilla
Copy link
Contributor Author

Added new C++ based loggers (see original post), which significantly speed up logging.

@juan-g-bonilla
Copy link
Contributor Author

It was discussed that it is best to separate C++ logging from this new logging system, pending further discussion on whether we actually want to encourage 'variable logging' as a form of simulation poking.

@juan-g-bonilla
Copy link
Contributor Author

Moreover, the possible merge of #317 might simplify the implementation of this PR (by leveraging the unified access to variables from the SysModel class for both C modules and C++ modules). Therefore, if #317 is expected to be approved withing the reasonable future, it might make sense to pause this PR until then. Thoughts?

@schaubh
Copy link
Contributor

schaubh commented May 4, 2023

Sure, this PR can wait for #317 to be approved if it will yield a nicer implementation. It will be nice to have this, but there is no immediate urgency.

@joaogvcarneiro joaogvcarneiro added the dont merge Waiting on other changes before merging label May 13, 2023
@juan-g-bonilla juan-g-bonilla force-pushed the feature/286-sysmodel-logger branch 2 times, most recently from 601129c to 37ca757 Compare September 8, 2023 00:05
@juan-g-bonilla juan-g-bonilla removed the dont merge Waiting on other changes before merging label Sep 8, 2023
@juan-g-bonilla juan-g-bonilla force-pushed the feature/286-sysmodel-logger branch 4 times, most recently from 850cfa8 to cc2dc22 Compare September 8, 2023 16:25
@schaubh
Copy link
Contributor

schaubh commented Sep 10, 2023

@juan-g-bonilla , Looking over your PR for this branch. Nice work overall, I'm not seeing any major issues. Some questions:

  • module swig files must be updated to include sys_model.i instead of sys_model.h, correct? This is regardless if the BSK python scrips uses module variable logging or not. If yes, we should add a warning to the Release notes that this version requires this small change. I reverse that swig file change for one module, compiled, and it still seemed to work. TO me at least this change in the swig file include wasn't required?
  • The old data logging method is still supported as a deprecated functionality. Can we keep the old document on logging a variable in a new RST file as you do with Deprecated: Using old-style C modules? The old method is still supported for 1 year as a depreciated functionality, so I feel we should keep some documentation on the old functionality around.

Copy link
Contributor

@joaogvcarneiro joaogvcarneiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change, makes it much easier. I added just a couple of comments, everything else looks great. Thanks, Juan!

src/utilities/pythonVariableLogger.py Show resolved Hide resolved
@juan-g-bonilla
Copy link
Contributor Author

@juan-g-bonilla , Looking over your PR for this branch. Nice work overall, I'm not seeing any major issues. Some questions:

* module swig files must be updated to include `sys_model.i` instead of `sys_model.h`, correct?  This is regardless if the BSK python scrips uses module variable logging or not.  If yes, we should add a warning to the Release notes that this version requires this small change.  I reverse that swig file change for one module, compiled, and it still seemed to work.  TO me at least this change in the swig file include wasn't required?

* The old data logging method is still supported as a deprecated functionality.  Can we keep the old document on logging a variable in a new RST file as you do with `Deprecated: Using old-style C modules`?  The old method is still supported for 1 year as a depreciated functionality, so I feel we should keep some documentation on the old functionality around.

Thanks for the review!

  • Using sys_model.i instead of sys_model.h only makes the logger function available. Not using it will not break the module, but you cannot use logger. However, because we don't know when users might need logger and to prevent inconsistency, I would recommend we just tell users to update to .i (the release note is a good idea). Moreover, if we ever need to further customize the python wrapper of sys model, we will have all models already importing .i.
  • I will bring back the old logging as a deprecated logging page!

Finally, I forgot to mention, there is a video tutorial that is now outdated (sorry!)

@schaubh
Copy link
Contributor

schaubh commented Sep 12, 2023

Ok, let's add a note in the release notes that module *.i files must be updated to take advantage of the new logging system. Yes, I'll have to create a new video ;-). I'll work on that video after you have made these final tweaks.

@juan-g-bonilla
Copy link
Contributor Author

@schaubh I implemented the small fixes, just waiting on the video for merging!

@schaubh
Copy link
Contributor

schaubh commented Sep 13, 2023

Ok, thanks @juan-g-bonilla , thanks for the update. I'll try to do the new video for the RST file ASAP.

@schaubh schaubh force-pushed the feature/286-sysmodel-logger branch 3 times, most recently from 7679f7e to 74e4e89 Compare September 14, 2023 19:24
Copy link
Contributor

@schaubh schaubh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR. This is a nice change. I chose not to redo the video as the variable logging is now so simple, and similar to how the recorder() method works, I didn't see a need for a video.

@schaubh schaubh merged commit d98b278 into develop Sep 15, 2023
2 checks passed
@schaubh schaubh deleted the feature/286-sysmodel-logger branch September 15, 2023 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants