def setUp(self):
        self.startdir = os.getcwd()
        self.tempdir = tempfile.mkdtemp(prefix='test_csv-')
        os.chdir(self.tempdir)

        self.top = top = set_as_top(Assembly())
        driver = top.add('driver', SimpleCaseIterDriver())
        top.add('comp1', ExecComp(exprs=['z=x+y']))
        top.add('comp2', ExecComp(exprs=['z=x+1']))
        top.connect('comp1.z', 'comp2.x')
        top.comp1.add('a_string', Str("Hello',;','", iotype='out'))
        top.comp1.add('a_array', Array(array([1.0, 3.0, 5.5]), iotype='out'))
        top.comp1.add('x_array', Array(array([1.0, 1.0, 1.0]), iotype='in'))
        top.comp1.add('b_bool', Bool(False, iotype='in'))
        top.comp1.add('vt', VarTree(DumbVT(), iotype='out'))
        top.driver.workflow.add(['comp1', 'comp2'])

        # now create some Cases
        outputs = ['comp1.z', 'comp2.z', 'comp1.a_string', 'comp1.a_array[2]']
        cases = []
        for i in range(10):
            i = float(i)
            inputs = [('comp1.x', i + 0.1), ('comp1.y', i * 2 + .1),
                      ('comp1.x_array[1]', 99.88), ('comp1.b_bool', True)]
            cases.append(Case(inputs=inputs, outputs=outputs))

        Case.set_vartree_inputs(driver, cases)
        driver.add_responses(sorted(outputs))

        self.filename = "openmdao_test_csv_case_iterator.csv"
Esempio n. 2
0
    def test_scid2(self):
        logging.debug('')
        logging.debug('test_simplecid')

        top = Assembly()
        top.add('generator', Generator())
        cid = top.add('cid', SimpleCaseIterDriver())
        top.add('driven', DrivenComponent())
        top.add('verifier', Verifier())

        top.driver.workflow.add(('generator', 'cid', 'verifier'))
        cid.workflow.add('driven')
        cid.add_parameter('driven.x')
        cid.add_parameter('driven.y')
        cid.add_response('driven.rosen_suzuki')
        cid.add_response('driven.sum_y')

        top.connect('generator.x', 'cid.case_inputs.driven.x')
        top.connect('generator.y', 'cid.case_inputs.driven.y')

        top.connect('generator.x', 'verifier.x')
        top.connect('generator.y', 'verifier.y')
        top.connect('cid.case_outputs.driven.rosen_suzuki',
                    'verifier.rosen_suzuki')
        top.connect('cid.case_outputs.driven.sum_y', 'verifier.sum_y')

        top.run()
 def setUp(self):
     self.top = top = set_as_top(Assembly())
     driver = top.add('driver', SimpleCaseIterDriver())
     top.add('comp1', ExecComp(exprs=['z=x+y']))
     top.add('comp2', ExecComp(exprs=['z=x+1']))
     top.connect('comp1.z', 'comp2.x')
     driver.workflow.add(['comp1', 'comp2'])
     
     # now create some Cases
     outputs = ['comp1.z', 'comp2.z']
     cases = []
     for i in range(10):
         inputs = [('comp1.x', i), ('comp1.y', i*2)]
         cases.append(Case(inputs=inputs, outputs=outputs, label='case%s'%i))
     driver.iterator = ListCaseIterator(cases)
Esempio n. 4
0
    def setUp(self):
        self.top = top = set_as_top(Assembly())
        driver = top.add('driver', SimpleCaseIterDriver())
        top.add('comp1', ExecComp(exprs=['z=x+y']))
        top.add('comp2', ExecComp(exprs=['z=x+1']))
        top.comp1.add('a_dict', Dict({}, iotype='in'))
        top.comp1.add('a_list', List([], iotype='in'))
        top.connect('comp1.z', 'comp2.x')
        driver.workflow.add(['comp1', 'comp2'])

        # now create some Cases
        outputs = ['comp1.z', 'comp2.z']
        cases = []
        for i in range(10):
            inputs = [('comp1.x', i), ('comp1.y', i * 2),
                      ('comp1.a_dict', {
                          'a': 'b'
                      }), ('comp1.a_list', ['a', 'b'])]
            cases.append(Case(inputs=inputs, outputs=outputs))
        Case.set_vartree_inputs(driver, cases)
        driver.add_responses(outputs)
Esempio n. 5
0
 def setUp(self):
     self.top = top = set_as_top(Assembly())
     driver = top.add('driver', SimpleCaseIterDriver())
     top.add('comp1', ExecComp(exprs=['z=x+y']))
     top.add('comp2', ExecComp(exprs=['z=x+1']))
     top.connect('comp1.z', 'comp2.x')
     top.comp1.add('a_string', Str("Hello',;','", iotype='out'))
     top.comp1.add('a_array', Array(array([1.0, 3.0, 5.5]), iotype='out'))
     top.comp1.add('x_array', Array(array([1.0, 1.0, 1.0]), iotype='in'))
     top.comp1.add('vt', Slot(DumbVT, iotype='out'))
     top.comp1.vt = DumbVT()
     driver.workflow.add(['comp1', 'comp2'])
     
     # now create some Cases
     outputs = ['comp1.z', 'comp2.z', 'comp1.a_string', 'comp1.a_array[2]']
     cases = []
     for i in range(10):
         inputs = [('comp1.x', i+0.1), ('comp1.y', i*2 + .1), ('comp1.x_array[1]', 99.88)]
         cases.append(Case(inputs=inputs, outputs=outputs, label='case%s'%i))
     driver.iterator = ListCaseIterator(cases)
     
     self.filename = "openmdao_test_csv_case_iterator.csv"
        self.top.recorders = [CSVCaseRecorder(filename=self.filename)]
        self.top.run()
        cases = [case for case in self.top.recorders[0].get_iterator()]
        end_case = cases[-1]
        #end_case.get_input('comp.dummy_data.dummy1')
        self.assertAlmostEqual(end_case.get_input('comp.dummy_data.dummy1'),
                               3.0, 1)  #3.0 should be minimum

    def test_inoutCSV(self):
        self.top = set_as_top(TestAssembly())
        self.top.recorders = [CSVCaseRecorder(filename=self.filename)]
        self.top.run()

        # now use the CSV recorder as source of Cases
        cases = [case for case in self.top.recorders[0].get_iterator()]
        driver = self.top.add('driver', SimpleCaseIterDriver())
        Case.set_vartree_inputs(self.top.driver, cases)

        sout = StringIO.StringIO()
        self.top.recorders = [DumpCaseRecorder(sout)]
        driver.add_responses([
            'comp.x',
        ])
        self.top.run()

        # Check the results
        expected = [
            "Case:",
            "   uuid: 2983e819-9c1b-11e4-804e-20c9d0478eff",
            "   timestamp: 1421260120.252554",
            "   inputs:",