Monte Carlo Dispersion Improvement#1402
Conversation
5f88e10 to
f42a999
Compare
andrewmorell
left a comment
There was a problem hiding this comment.
A few issues here that I think need to be fixed and a few things that are optional. Feels like a good thing we're addressing but needs some more refinement.
Also a heads up that there are a number of next-door issues in dispersions.py that will surface with controller.py fixed. UniformVectorAngleDispersion(), NormalVectorAngleDispersion(), NormalVectorAngleDispersion(), NormalThrusterUnitDirectionVectorDispersion(), and maybe others use getattr() which can't resolve the nested paths that the controller now correctly writes.
f42a999 to
19b72e8
Compare
19b72e8 to
9f22c0b
Compare
andrewmorell
left a comment
There was a problem hiding this comment.
Found a few more things on this pass. In particular the double index nested paths edge case and next door bugs in dispersions.py feel in need of applying now, everything else is minor.
Also please give a few bread crumbs as to where/how feedback is implemented. It took a while to hunt down changes corresponding to one word replies.
Replace direct setattr() on full Monte Carlo path strings with a shared path resolver that traverses dotted attributes, integer indices, and zero-argument accessor methods without eval or exec. This lets archived parameters, generated dispersions, and RNG seed modifications update the actual simulation objects instead of creating literal top-level attributes. Reuse the same resolver for dispersion generators that need to read nominal nested values, and write indexed mutations back to their owning attributes so copy-on-read SWIG/Eigen containers such as voltage2TorqueGain[0] are not silently discarded. Add focused unit coverage for nested attributes, accessor paths, SWIG indexed containers, RNG seeds before configureFunction, and generated UniformDispersion values reaching the live simulation object.
Tune scenarioMonteCarloAttRW dispersions so the example shows subtle run-to-run variation without driving the response into saturation. Keep the nominal RW speed values readable in RPM, but convert the dispersion bounds to rad/s before applying them to the RW*.Omega fields. Fix the scenario figure-saving path so saved documentation figures accumulate all Monte Carlo traces, add a retained-trajectory comparison to catch identical-run regressions, and repair the RST grid table with explicit inertia units.
Add the release-note snippet for the Monte Carlo dispersion fix and record the resolved known issue for the current release. Keep this metadata separate from the framework and scenario commits so release-note changes are easy to review.
Extend the Monte Carlo nested-attribute setter to handle trailing integer index chains, such as Eigen Matrix3d paths of the form scObject.hub.IHubPntBc_B[0][1]. The setter now updates the deepest indexed value, writes each indexed container back up the path, and finally writes the full container back to the owning SWIG attribute. Add a unit test using a real Basilisk spacecraft hub Matrix3d to verify that double-indexed modifications propagate through the SWIG layer. Also update the Monte Carlo README to document repeated bracket indexing for matrix-like attributes.
Store the NormalVectorDispersion mean and stdDeviation constructor arguments on the dispersion instance so generated values use the configured normal distribution parameters. Also update generate() to call the shared normal-vector helper consistently, since the helper reads the stored statistics from self. Add a deterministic regression test with zero standard deviation to verify that NormalVectorDispersion honors a configured mean value.
Use the absolute phi and theta bounds computed from the nominal vector directly when sampling UniformVectorAngleDispersion values. The previous logic added the nominal phi/theta twice, shifting the sampling interval to be centered around roughly twice the nominal angle. Add a regression test with a non-axis nominal vector that records the np.random.uniform() intervals and verifies they are centered on the nominal vector angle plus the configured off-nominal bounds.
9f22c0b to
1aae0ad
Compare
Update NormalVectorAngleDispersion to draw scalar phi/theta samples instead of one-element NumPy arrays. The previous size=1 calls caused magnitude generation to fail when round() received an ndarray. Add a regression test that records the np.random.normal() calls and verifies the dispersion uses scalar sample arguments while still producing a normalized output vector and valid sigma magnitudes.
andrewmorell
left a comment
There was a problem hiding this comment.
Looking good to go now!
Description
Fixes BSK issue #1164 reported by ruthubotica by replacing the Monte Carlo executor’s direct
setattr(simInstance, path, value)call with a nested path resolver. The resolver now applies dispersions and archived modifications to the actual simulation objects, including dotted attributes, integer list indices, and existing zero-argument accessor paths such asget_DynModel().scObject.hub.r_CN_NInit.The branch also routes saved
RNGSeedupdates through the same application helper, ensures seeds are populated beforeconfigureFunction, and tunesscenarioMonteCarloAttRWdispersions/plot saving so the documented Monte Carlo results show subtle run-to-run variation rather than overlapping or saturated responses.Commits are organized as controller/test fix, scenario/documentation update, and release-note/known-issue updates.
Verification
Added focused unit tests in
src/utilities/MonteCarlo/_UnitTests/test_controller.pycovering nested attribute updates, indexed list updates, zero-argument accessor paths, archivedRNGSeedapplication before configuration, and generatedUniformDispersionvalues reaching the live simulation object.Validated with:
Documentation
Updated Monte Carlo README guidance to describe when seeds and non-seed dispersions are applied, and to document nested path support including zero-argument accessor methods.
Updated
scenarioMonteCarloAttRWdocumentation/table to match the revised subtler dispersions and clarify nested dispersion paths. Added a release note snippet and updated known issues to mention the Monte Carlo dispersion application fix.Reviewers should check the updated scenario dispersion table and the README’s description of configure/dispersal ordering.
Future work
No required follow-up is known.