Skip to content

Commit 483cacf

Browse files
ddj116Dan Jordan
andauthored
MonteCarloGenerate: Provide more metadata on dispersions (#1608)
* Add type, dispersion, min_value, max_value and other relevant internal members of MonteCarloVariable* classes to the output of MonteCarlo_Meta_data_output. Motivation is for users wanting to post-process dispersion parameters used during generation of runs * Protect against invalid memory access when length of values is zero in MonteCarloVariableRandomStringSet::generate_assignment(). Add a new verif sim warning case to cover these new lines * Update new verif data for SIM_mc_generation to support these changes Closes #1574 Co-authored-by: Dan Jordan <daniel.d.jordan@nasa.gov>
1 parent 9ead0a2 commit 483cacf

File tree

16 files changed

+226
-61
lines changed

16 files changed

+226
-61
lines changed

include/trick/mc_variable.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ class MonteCarloVariable
6565
const std::string & get_command() const {return command;}
6666
const std::string & get_variable_name() const {return variable_name;}
6767
const std::string & get_assignment() const {return assignment;}
68-
MonteCarloVariableType get_type() const {return type;}
68+
virtual MonteCarloVariableType get_type() const {return type;}
69+
virtual std::string get_type_str() const;
6970
virtual unsigned int get_seed() const {return 0;}
71+
virtual std::string summarize_variable() const;
7072

7173
protected:
7274
void insert_units();

include/trick/mc_variable_file.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class MonteCarloVariableFile : public MonteCarloVariable
6868
virtual ~MonteCarloVariableFile(){};
6969
void initialize_file();
7070
void generate_assignment();
71+
virtual std::string summarize_variable() const;
72+
7173
void register_dependent( MonteCarloVariableFile *);
7274
virtual void shutdown() {file.close();}
7375

include/trick/mc_variable_random.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class MonteCarloVariableRandom : public MonteCarloVariable
4040
virtual ~MonteCarloVariableRandom(){};
4141
unsigned int get_seed() const {return seed_m;} // override but SWIG cannot process the
4242
// override keyword
43-
4443
private: // and undefined:
4544
MonteCarloVariableRandom( const MonteCarloVariableRandom & );
4645
MonteCarloVariableRandom& operator = (const MonteCarloVariableRandom&);

include/trick/mc_variable_random_normal.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class MonteCarloVariableRandomNormal : public MonteCarloVariableRandom
4444

4545
virtual ~MonteCarloVariableRandomNormal(){};
4646
virtual void generate_assignment();
47+
virtual std::string summarize_variable() const;
4748
void truncate(double limit, TruncationType type = StandardDeviation);
4849
void truncate(double min, double max, TruncationType type = StandardDeviation);
4950
void truncate_low(double limit, TruncationType type = StandardDeviation);

include/trick/mc_variable_random_string.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class MonteCarloVariableRandomStringSet : public MonteCarloVariableRandomUniform
4343

4444
virtual ~MonteCarloVariableRandomStringSet(){};
4545
virtual void generate_assignment();
46+
virtual std::string summarize_variable() const;
4647
void add_string(std::string);
4748
private: // and undefined:
4849
MonteCarloVariableRandomStringSet(const MonteCarloVariableRandomStringSet&);

include/trick/mc_variable_random_uniform.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class MonteCarloVariableRandomUniform : public MonteCarloVariableRandom
3535
double upper_bound = 1.0);
3636
virtual ~MonteCarloVariableRandomUniform(){};
3737
virtual void generate_assignment();
38+
virtual std::string summarize_variable() const;
3839
private: // and undefined:
3940
MonteCarloVariableRandomUniform( const MonteCarloVariableRandomUniform & );
4041
MonteCarloVariableRandomUniform& operator = (
@@ -59,6 +60,7 @@ class MonteCarloVariableRandomUniformInt : public MonteCarloVariableRandom
5960
double upper_bound = 1);
6061
virtual ~MonteCarloVariableRandomUniformInt(){};
6162
virtual void generate_assignment();
63+
virtual std::string summarize_variable() const;
6264
private: // and undefined:
6365
MonteCarloVariableRandomUniformInt(const MonteCarloVariableRandomUniformInt&);
6466
MonteCarloVariableRandomUniformInt& operator = (
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
monte_carlo.mc_master.activate("RUN_WARN_no_string_values")
2+
monte_carlo.mc_master.set_num_runs(1)
3+
4+
print('*********************************************************************************')
5+
print('this message is expected:')
6+
print('No values for MonteCarloVariableRandomStringSet')
7+
print('Length of values vector is zero for variable: test.x_string, Did you forget to call add_string()?')
8+
print('*********************************************************************************')
9+
10+
11+
# add a string variable but forget to give it options to randomize
12+
mc_var = trick.MonteCarloVariableRandomStringSet( "test.x_string", 3)
13+
#mc_var.add_string("\"ABC\"")
14+
#mc_var.add_string("\"DEF\"")
15+
#mc_var.add_string("'GHIJKL'")
16+
mc_var.thisown = False
17+
monte_carlo.mc_master.add_variable(mc_var)
18+
monte_carlo.mc_master.generate_meta_data = True
19+

test/SIM_mc_generation/verif_data/MONTE_RUN_nominal/MonteCarlo_Meta_data_output

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@
1010
- 0 variables of undefined type
1111

1212
********************* LIST OF VARIABLES, TYPES****************
13-
test.x_boolean, Random
14-
test.x_file_lookup[0], Prescribed
15-
test.x_file_lookup[1], Prescribed
16-
test.x_file_lookup[2], Prescribed
17-
test.x_fixed_value_double, Constant
18-
test.x_fixed_value_int, Constant
19-
test.x_fixed_value_string, Constant
20-
test.x_integer, Random
21-
test.x_line_command, Calculated
22-
test.x_normal, Random
23-
test.x_normal_length, Random
24-
test.x_normal_trunc[0], Random
25-
test.x_normal_trunc[1], Random
26-
test.x_normal_trunc[2], Random
27-
test.x_normal_trunc[3], Random
28-
test.x_normal_trunc[4], Random
29-
test.x_semi_fixed_value, Constant
30-
test.x_string, Random
31-
test.x_uniform, Random
13+
test.x_boolean: type=Random, dispersion=Uniform, min_value=0, max_value=1, seed=4, values=[False,True,]
14+
test.x_file_lookup[0]: type=Prescribed, max_skip=0, is_dependent=0, filename=Modified_data/datafile.txt, column_number=3, first_column_number=1
15+
test.x_file_lookup[1]: type=Prescribed, max_skip=0, is_dependent=1, filename=Modified_data/datafile.txt, column_number=2, first_column_number=1
16+
test.x_file_lookup[2]: type=Prescribed, max_skip=0, is_dependent=1, filename=Modified_data/datafile.txt, column_number=1, first_column_number=1
17+
test.x_fixed_value_double: type=Constant
18+
test.x_fixed_value_int: type=Constant
19+
test.x_fixed_value_string: type=Constant
20+
test.x_integer: type=Random dispersion=Uniform, min_value=0, max_value=2, seed=1
21+
test.x_line_command: type=Calculated
22+
test.x_normal: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=0, max_value=0, seed=2
23+
test.x_normal_length: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=0, max_value=0, seed=2
24+
test.x_normal_trunc[0]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=9, max_value=11, seed=2
25+
test.x_normal_trunc[1]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=9.5, max_value=10.7, seed=2
26+
test.x_normal_trunc[2]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=9.9, max_value=11, seed=2
27+
test.x_normal_trunc[3]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=9.9, max_value=0, seed=2
28+
test.x_normal_trunc[4]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=0, max_value=4, seed=2
29+
test.x_semi_fixed_value: type=Constant
30+
test.x_string: type=Random, dispersion=Uniform, min_value=0, max_value=1, seed=3, values=["ABC","DEF",'GHIJKL',]
31+
test.x_uniform: type=Random, dispersion=Uniform, min_value=10, max_value=20, seed=0
3232
**************************************************************
3333

3434

3535
*********** LIST OF EXECUTABLE FILES AND FUNCTIONS ***********
36-
test.standalone_function( test.x_normal)
36+
test.standalone_function( test.x_normal): type=Execute
3737
***
38-
Modified_data/sample.py
38+
Modified_data/sample.py: type=Execute
3939
***
4040
**************************************************************
4141

test/SIM_mc_generation/verif_data/MonteCarlo_Meta_data_output

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@ Sending meta-data to top-level directory.
1414
- 0 variables of undefined type
1515

1616
********************* LIST OF VARIABLES, TYPES****************
17-
test.x_boolean, Random
18-
test.x_file_lookup[0], Prescribed
19-
test.x_file_lookup[1], Prescribed
20-
test.x_file_lookup[2], Prescribed
21-
test.x_fixed_value_double, Constant
22-
test.x_fixed_value_int, Constant
23-
test.x_fixed_value_string, Constant
24-
test.x_integer, Random
25-
test.x_line_command, Calculated
26-
test.x_normal, Random
27-
test.x_normal_length, Random
28-
test.x_normal_trunc[0], Random
29-
test.x_normal_trunc[1], Random
30-
test.x_normal_trunc[2], Random
31-
test.x_normal_trunc[3], Random
32-
test.x_normal_trunc[4], Random
33-
test.x_semi_fixed_value, Constant
34-
test.x_string, Random
35-
test.x_uniform, Random
17+
test.x_boolean: type=Random, dispersion=Uniform, min_value=0, max_value=1, seed=4, values=[False,True,]
18+
test.x_file_lookup[0]: type=Prescribed, max_skip=0, is_dependent=0, filename=Modified_data/datafile.txt, column_number=3, first_column_number=1
19+
test.x_file_lookup[1]: type=Prescribed, max_skip=0, is_dependent=1, filename=Modified_data/datafile.txt, column_number=2, first_column_number=1
20+
test.x_file_lookup[2]: type=Prescribed, max_skip=0, is_dependent=1, filename=Modified_data/datafile.txt, column_number=1, first_column_number=1
21+
test.x_fixed_value_double: type=Constant
22+
test.x_fixed_value_int: type=Constant
23+
test.x_fixed_value_string: type=Constant
24+
test.x_integer: type=Random dispersion=Uniform, min_value=0, max_value=2, seed=1
25+
test.x_line_command: type=Calculated
26+
test.x_normal: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=0, max_value=0, seed=2
27+
test.x_normal_length: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=0, max_value=0, seed=2
28+
test.x_normal_trunc[0]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=9, max_value=11, seed=2
29+
test.x_normal_trunc[1]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=9.5, max_value=10.7, seed=2
30+
test.x_normal_trunc[2]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=9.9, max_value=11, seed=2
31+
test.x_normal_trunc[3]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=9.9, max_value=0, seed=2
32+
test.x_normal_trunc[4]: type=Random, dispersion=Normal, mean=10, stddev=2, min_value=0, max_value=4, seed=2
33+
test.x_semi_fixed_value: type=Constant
34+
test.x_string: type=Random, dispersion=Uniform, min_value=0, max_value=1, seed=3, values=["ABC","DEF",'GHIJKL',]
35+
test.x_uniform: type=Random, dispersion=Uniform, min_value=10, max_value=20, seed=0
3636
**************************************************************
3737

3838

3939
*********** LIST OF EXECUTABLE FILES AND FUNCTIONS ***********
40-
test.standalone_function( test.x_normal)
40+
test.standalone_function( test.x_normal): type=Execute
4141
***
42-
Modified_data/sample.py
42+
Modified_data/sample.py: type=Execute
4343
***
4444
**************************************************************
4545

test_sims.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ SIM_mc_generation:
447447
RUN_WARN_overconstrained_config/input.py:
448448
compare:
449449
phase: -1
450+
RUN_WARN_no_string_values/input.py:
451+
compare:
452+
phase: -1
450453
MONTE_RUN_WARN_overconstrained_config/RUN_0/monte_input.py:
451454
FAIL_config_error/input.py:
452455
returns: 1

0 commit comments

Comments
 (0)