1+ #
2+ # Copyright IBM Corporation 2021
3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ #
8+ # http://www.apache.org/licenses/LICENSE-2.0
9+ #
10+ # Unless required by applicable law or agreed to in writing, software
11+ # distributed under the License is distributed on an "AS IS" BASIS,
12+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ # See the License for the specific language governing permissions and
14+ # limitations under the License.
15+ #
16+
17+ # Run mock script:
18+ # $ python doframework_mock.py -c configs.yaml
19+
20+ import argparse
21+ import numpy as np
22+ import doframework as dof
23+ from doframework .core .optimizer import predict_optimize
24+ from doframework .core .storage import Storage
25+ from doframework .core .inputs import get_configs
26+
27+ @dof .resolve
28+ def predict_optimize_resolved (data : np .array , constraints : np .array , ** kwargs ):
29+ return predict_optimize (data , constraints , ** kwargs )
30+
31+ if __name__ == '__main__' :
32+
33+ parser = argparse .ArgumentParser ()
34+ parser .add_argument ("-c" , "--configs" , type = str , help = "Path to user configs.yaml relative to current working directory." )
35+ parser .add_argument ("-o" , "--objectives" , type = int , default = 3 , help = "Number of objectives to generate per meta input (default: 3)." )
36+ parser .add_argument ("-d" , "--datasets" , type = int , default = 2 , help = "Number of datasets to generate per objective (default: 2)." )
37+ parser .add_argument ("-r" , "--feasibility_regions" , type = str , default = 1 , help = "Number of feasibility regions to generate per dataset (default: 1)." )
38+ args = parser .parse_args ()
39+
40+ configs = get_configs (args .configs )
41+ storage = Storage (configs )
42+ buckets = storage .buckets ()
43+
44+ num_inputs_at_start = storage .count (buckets ['inputs' ],'json' )+ storage .count (buckets ['inputs_dest' ],'json' )
45+ num_objectives_at_start = storage .count (buckets ['objectives' ],'json' )+ storage .count (buckets ['objectives_dest' ],'json' )
46+ num_datasets_at_start = storage .count (buckets ['data' ],'csv' )+ storage .count (buckets ['data_dest' ],'csv' )
47+ num_solutions_at_start = storage .count (buckets ['solutions' ],'json' )+ storage .count (buckets ['solutions_dest' ],'json' )
48+
49+ expected_objectives = args .objectives
50+ expected_datasets = expected_objectives * args .datasets
51+ expected_solutions = expected_datasets * args .feasibility_regions
52+
53+ bucket = buckets ['inputs' ]
54+ name = 'input_test.json'
55+ content = {"data" : {"N" : 500 , "noise" : 0.01 }, "input_file_name" : name }
56+ response = storage .put (bucket ,content ,name ,'json' )
57+ assert response , 'Failed to upload test input file to inputs bucket.'
58+
59+ dof .run (
60+ predict_optimize_resolved ,
61+ args .configs ,
62+ objectives = args .objectives ,
63+ datasets = args .datasets ,
64+ feasibility_regions = args .feasibility_regions ,
65+ after_idle_for = 60 ,
66+ logger = True ,
67+ mock = True # mock mode
68+ )
69+
70+ num_inputs = storage .count (buckets ['inputs' ],'json' )+ storage .count (buckets ['inputs_dest' ],'json' )- num_inputs_at_start
71+ num_objectives = storage .count (buckets ['objectives' ],'json' )+ storage .count (buckets ['objectives_dest' ],'json' )- num_objectives_at_start
72+ num_datasets = storage .count (buckets ['data' ],'csv' )+ storage .count (buckets ['data_dest' ],'csv' )- num_datasets_at_start
73+ num_solutions = storage .count (buckets ['solutions' ],'json' )+ storage .count (buckets ['solutions_dest' ],'json' )- num_solutions_at_start
74+
75+ print (f'SANITY: compare the number of generated files to the expected:' )
76+ print (f'Generated { num_objectives } objectives out of expected { expected_objectives } .' )
77+ print (f'Generated { num_datasets } datasets out of expected { expected_datasets } .' )
78+ print (f'Generated { num_solutions } solutions out of expected { expected_solutions } .' )
0 commit comments