trick/trick_source/trick_swig/sim_services.i
ddj116 9099792947
Integrate MonteCarloGenerate capability from EG CML and associated TrickOps enhancements (#1415)
* Provide MonteCarloGenerate capability

Intermediate commit, this squash represents all of Isaac Reaves' work
during his Fall 2022 Pathways internship tour

[skip ci]

* TrickOps: Add phase, [min-max] range, and overhaul YAML verification

* Add new "phase:" mechanism to TrickOps Runs and Builds to support
  project-specific constraints on build and run ordering
  - phase defaults to zero if not specified and must be between -1000
    and 1000 if given.
  - jobs can now optionally be requested by their phase or phase range
  - See trickops/README.md for details
* Add [min-max] notation capability to run: entries and compare: entries
  - [min-max] ranges provide definition of a set of runs using a common
    numbering scheme in the YAML file, greatly reducing YAML file size
    for monte-carlo and other zero-padded run numbering use cases
  - See trickops/README.md for details
* YAML parsing changes
  - Overhaul the logic which verifies YAML files for the expected
    TrickOps format. This is now done in TrickWorkflowYamlVerifier and
    provides much more robust error checking than previous approach
  - .yaml_requirements.yml now provides the required types, ranges, and
    default values as applicable to expected entries in YAML files
  - valgrind: is now an sub-option to run: entries, not its own section
    Users should now list their runs normallly and define their flags in
    in that run's valgrind: subsection
  - parallel_safety is now a per-sim parameter and not global. Users
    should move their global config to the sim layer
  - self.config_errors is now a list of errors. Users should now
    check for empty list when using instead of True/False
* Robustify the get_koviz_report_jobs unit test to work whether koviz
  exists on PATH or not
* Adjust trickops.py to use the new phase and range features
   - Make it more configurable on the command-line via argparse
   - Move SIM_mc_generation tests into test_sims.yml

[skip ci]

* Code review and cleanup from PR #1389

Documentation:

* Adjust documentation to fit suggested symlinked approach. Also
  cleaned up duplicate images and old documentation.
* Moved the verification section out of markdown and into a PDF since it
  heavily leverages formatting not available in markdown.
* Clarify a couple points on the Darwin Trick install guide
* Update wiki to clarify that data recording strings is not supported

MCG Code:

* Replace MonteCarloVariableRandomNormal::is_near_equal with new
  Trick::dbl_is_near from trick team

MCG Testing:

* Reduce the set of SIM_mc_generation comparisons. After discussion
  the trick team, we are choosing to remove all comparisons to
  verif_data/ which contain random-generated numbers since
  these tests cannot pass across all supported trick platforms.
* Fix the wrong rule on exlcuding -Werror for Darwin builds
  of SIM_mc_generation
* Remove data recording of strings in SIM_mc_generation

Trickops:

* Replace build_command with build_args per discussion w/ Trick team
  Since we only support arguments to trick-CP, replace the build_command
  yaml entry with build_args
* Disable var server connection by default in SingleRun if TrickWorkflow.quiet
  is True
* Guard against multiple Job starts
* Remove SimulationJob inheritance layer since old monte-carlo wasn't
  and never will be supported by TrickOps
* Ignore IOError raise from variable_server that looks like "The remote
  endpoint has closed the connection". This appears to occur when
  SingleRun jobs attempt to connect to the var server for a sim that
  terminates very early

[skip ci]

* Adjust phasing of old/new MCG initialize functions

* Clarify failure message in generate_dispersions if new/old MC are both
  used.
* Adjust the phasing order of MCG intialize method to be before
  legacy MC initialized. Without this, monte-carlo dry run completes with
  success before the check in generate_dispersions() can run
* Add -Wno-stringop-truncation to S_override.mk for SIM_mc_generation
  since gcc 8+ warns about SWIG generated content in top.cpp

* Introduce MonteCarloGenerationHelper python class

This new class provides an easy-to-use interface for MCG sim-module
users:

1. Run generation
2. Getting an sbatch array job suitable for SLURM
3. Getting a list of SingleRun() instances for generated runs, to be
   executed locally if desired

---------

Co-authored-by: Dan Jordan <daniel.d.jordan@nasa.gov>
2023-03-06 09:25:50 -06:00

186 lines
5.8 KiB
OpenEdge ABL

%module sim_services
%{
#include <cstddef>
#include <random>
%}
#include "trick/swig/trick_swig.i"
#include "trick/swig/swig_class_typedef.i"
#include "trick/swig/cast_as.i"
#include "units_attach.i"
#include "extra_functions.i"
// Special typemap for collectee in add_collect and delete_collect.
%typemap(in) void * collectee {
// VOID *
void * argp2 ;
if ( SWIG_IsOK(SWIG_ConvertPtr($input, &argp2,SWIG_TypeQuery("void *"), 0)) ) {
// We have an address coming in, we don't have to do any translation
$1 = reinterpret_cast< $1_basetype * >(argp2) ;
} else if ( SWIG_IsOK(SWIG_ConvertPtr($input, &argp2,SWIG_TypeQuery("swig_ref *"), 0)) ) {
// Array to pointer assignment
swig_ref * temp_swig_ref = reinterpret_cast< swig_ref * >(argp2);
if ( temp_swig_ref != NULL ) {
$1 = ($1_basetype *)temp_swig_ref->ref.address ;
}
// package the array address as a void
}
}
%inline %{
#include "trick/swig/swig_global_vars.hh"
#include "trick/reference_frame.h"
#include "trick/rand_generator.h"
#include "trick/wave_form.h"
#include "trick/integrator_c_intf.h"
#include "trick/units_conv.h"
#include "trick/GetTimeOfDayClock.hh"
#include "trick/clock_proto.h"
#include "trick/CommandLineArguments.hh"
#include "trick/command_line_protos.h"
#include "trick/DRAscii.hh"
#include "trick/DRBinary.hh"
#ifdef HDF5
#include "trick/DRHDF5.hh"
#endif
#include "trick/DataRecordDispatcher.hh"
#include "trick/data_record_proto.h"
#include "trick/DebugPause.hh"
#include "trick/debug_pause_proto.h"
#include "trick/EchoJobs.hh"
#include "trick/echojobs_proto.h"
#include "trick/Environment.hh"
#include "trick/env_proto.h"
#include "trick/Executive.hh"
#include "trick/ExecutiveException.hh"
#include "trick/exec_proto.h"
#include "trick/exec_proto.hh"
#include "trick/MalfunctionsTrickView.hh"
#include "trick/MonteMonitor.hh"
#include "trick/SimControlPanel.hh"
#include "trick/StripChart.hh"
#include "trick/TrickView.hh"
#include "trick/ExternalApplicationManager.hh"
#include "trick/external_application_c_intf.h"
#include "trick/FrameDataRecordGroup.hh"
#include "trick/FrameLog.hh"
#include "trick/framelog_proto.h"
#include "trick/IPPython.hh"
#include "trick/input_processor_proto.h"
#include "trick/MTV.hh"
#include "trick/EventManager.hh"
#include "trick/EventProcessor.hh"
#include "trick/EventManager_c_intf.hh"
#include "trick/JITInputFile.hh"
#include "trick/jit_input_file_proto.hh"
#include "trick/JSONVariableServer.hh"
#include "trick/IntegLoopScheduler.hh"
#include "trick/IntegLoopManager.hh"
#include "trick/IntegLoopSimObject.hh"
#include "trick/Integrator.hh"
#include "trick/regula_falsi.h"
#include "trick/ABM_Integrator.hh"
#include "trick/Euler_Cromer_Integrator.hh"
#include "trick/Euler_Integrator.hh"
#include "trick/MM4_Integrator.hh"
#include "trick/NL2_Integrator.hh"
#include "trick/RK2_Integrator.hh"
#include "trick/RK4_Integrator.hh"
#include "trick/RKF45_Integrator.hh"
#include "trick/RKF78_Integrator.hh"
#include "trick/RKG4_Integrator.hh"
#include "trick/SimTime.hh"
#include "trick/simtime_proto.h"
#include "trick/MSSocket.hh"
#include "trick/MSSharedMem.hh"
#include "trick/Master.hh"
#include "trick/mc_master.hh"
#include "trick/mc_python_code.hh"
#include "trick/mc_variable_file.hh"
#include "trick/mc_variable_fixed.hh"
#include "trick/mc_variable.hh"
#include "trick/mc_variable_random_bool.hh"
#include "trick/mc_variable_random.hh"
#include "trick/mc_variable_random_normal.hh"
#include "trick/mc_variable_random_string.hh"
#include "trick/mc_variable_random_uniform.hh"
#include "trick/mc_variable_semi_fixed.hh"
#include "trick/Slave.hh"
#include "trick/master_proto.h"
#include "trick/MemoryManager.hh"
#include "trick/memorymanager_c_intf.h"
#include "trick/CheckPointRestart.hh"
#include "trick/CheckPointRestart_c_intf.hh"
#include "trick/collect_proto.hh"
#include "trick/AttributesMap.hh"
#include "trick/sie_c_intf.h"
#include "trick/MessageCout.hh"
#include "trick/MessageThreadedCout.hh"
#include "trick/MessageFile.hh"
#include "trick/MessageLCout.hh"
#include "trick/MessagePublisher.hh"
#include "trick/MessageSubscriber.hh"
#include "trick/MessageTCDevice.hh"
#include "trick/Message_proto.hh"
#include "trick/message_proto.h"
#include "trick/MonteCarlo.hh"
#include "trick/montecarlo_c_intf.h"
#include "trick/MonteVarCalculated.hh"
#include "trick/MonteVarFile.hh"
#include "trick/MonteVarFixed.hh"
#include "trick/MonteVarRandom.hh"
#include "trick/RealtimeSync.hh"
#include "trick/realtimesync_proto.h"
#include "trick/RtiExec.hh"
#include "trick/RtiStager.hh"
#include "trick/ITimer.hh"
#include "trick/Unit.hh"
#include "trick/UnitTest.hh"
#include "trick/trick_tests.h"
#include "trick/VariableServer.hh"
#include "trick/variable_server_proto.h"
#include "trick/vval.h"
#include "trick/Flag.h"
#include "trick/UdUnits.hh"
#include "trick/MyCivetServer.hh"
#ifdef USE_ER7_UTILS_INTEGRATORS
#include "er7_utils/integration/core/include/integrator_constructor_factory.hh"
#include "er7_utils/integration/core/include/integrable_object.hh"
#include "er7_utils/integration/core/include/base_integration_group.hh"
#include "er7_utils/trick/integration/include/trick_first_order_ode_integrator.hh"
#include "er7_utils/trick/integration/include/trick_second_order_ode_integrator.hh"
#endif
%}
%pythoncode %{
import os
import linecache
import re
curr_dir = os.getcwd()
exclude_dir = os.getcwd() + "/trick"
def traceit(frame, event, arg):
if event == "line":
lineno = frame.f_lineno
filename = frame.f_code.co_filename
if ( not filename.startswith(exclude_dir) and not filename.startswith("/usr")):
if (filename.endswith(".pyc") or
filename.endswith(".pyo")):
filename = filename[:-1]
line = linecache.getline(filename, lineno)
print (filename,":",lineno,": ",line.rstrip())
return traceit
%}