def test_case_recording(self): cds_path = os.path.join(os.path.dirname(__file__), "cds.json") asm = set_as_top(SellarProblem()) asm.architecture = MDF() asm.recorders = [JSONCaseRecorder(cds_path)] asm.run() cds = CaseDataset(cds_path, 'json') data = cds.data.by_variable().fetch() self.assertFalse(set(asm.solution.keys()) - set(data.keys())) for var in asm.solution.keys(): self.assertTrue(data[var]) np.allclose(data[var], asm.solution[var]) del cds del data os.remove(cds_path)
Problem forumulation is specified, and MDF is automatically set up for you. """ from openmdao.lib.architectures.api import MDF, BLISS, CO from openmdao.lib.casehandlers.api import DBCaseRecorder from openmdao.lib.optproblems.api import SellarProblem if __name__ == "__main__": # pragma: no cover import time from openmdao.main.api import set_as_top prob = SellarProblem() prob.architecture = MDF() prob.configure() prob.driver.recorders = [DBCaseRecorder()] tt = time.time() prob.run() error = prob.check_solution() print "\nUsing MDF Architecture" print "Minimum found at (%f, %f, %f)" % (prob.dis1.z1, prob.dis1.z2, prob.dis1.x1) print "Minimum differs from expected by (%f, %f, %f)" % ( error["z1"], error["z2"], error['dis1.x1'])
for i in range(0, prob_size): #only need one target for each global parts.append('d0.z[%d][0]**2' % i) for d in self.disciplines: for j in range(0, prob_size): parts.append("%s.y_out[%d][0]**2" % (d, j)) self.add_objective("+".join(parts), name="obj1") self.solution['obj1'] = float(n_disciplines) * prob_size if __name__ == '__main__': from openmdao.lib.architectures.api import MDF sp = UnitScalableProblem(3) sp.architecture = MDF() sp.run() error = sp.check_solution() for k, v in sp.solution.iteritems(): print k, v print #print sp.d0.x0 for k, v in error.iteritems(): print k, v #print sum([v**2 for k,v in error.iteritems()])**.5
if __name__=="__main__": from openmdao.lib.architectures.api import IDF, MDF, CO, BLISS, BLISS2000 def display_results(): print "Minimum found at (%f, %f, %f)" % (problem.dis1.z1, problem.dis1.z2, problem.dis1.x1) print "Couping vars: %f, %f" % (problem.dis1.y1, problem.dis2.y2) print "Function calls dis1: %d, dis2: %d"%(problem.dis1.exec_count,problem.dis2.exec_count) print "\n" print "Running SellarProblem with MDF" problem = SellarProblem() problem.architecture = MDF() problem.run() display_results() print "Running SellarProblem with CO" problem = SellarProblem() problem.architecture = CO() problem.run() display_results() print "Running SellarProblem with BLISS" problem = SellarProblem() problem.architecture = BLISS() problem.run()