<s> """<STR_LIT>""" <EOL> import os . path <EOL> import tempfile <EOL> import shutil <EOL> import unittest <EOL> from unittest import SkipTest <EOL> from math import isnan <EOL> from openmdao . main . api import Assembly , Component , VariableTree , set_as_top <EOL> from openmdao . main . datatypes . api import Array , Float , VarTree <EOL> from openmdao . lib . drivers . api import FixedPointIterator , SLSQPdriver <EOL> from openmdao . lib . optproblems import sellar <EOL> from openmdao . util . testutil import assert_rel_error <EOL> class States ( VariableTree ) : <EOL> y = Array ( [ <NUM_LIT:0.0> , <NUM_LIT:0.0> ] ) <EOL> class Globals ( VariableTree ) : <EOL> z1 = Float ( <NUM_LIT:0.0> ) <EOL> z2 = Float ( <NUM_LIT:0.0> ) <EOL> class Half ( Component ) : <EOL> z2a = Float ( <NUM_LIT:0.0> , iotype = '<STR_LIT>' ) <EOL> z2b = Float ( <NUM_LIT:0.0> , iotype = '<STR_LIT>' ) <EOL> def execute ( self ) : <EOL> self . z2b = <NUM_LIT:0.5> * self . z2a <EOL> class SellarMDF ( Assembly ) : <EOL> """<STR_LIT>""" <EOL> def configure ( self ) : <EOL> """<STR_LIT>""" <EOL> sub = self . add ( '<STR_LIT>' , Assembly ( ) ) <EOL> sub . add ( '<STR_LIT>' , FixedPointIterator ( ) ) <EOL> sub . add ( '<STR_LIT>' , sellar . Discipline1 ( ) ) <EOL> sub . add ( '<STR_LIT>' , sellar . Discipline2 ( ) ) <EOL> sub . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> sub . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sub . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sub . driver . add_parameter ( '<STR_LIT>' ) <EOL> sub . driver . add_constraint ( '<STR_LIT>' ) <EOL> sub . driver . max_iteration = <NUM_LIT:100> <EOL> sub . driver . tolerance = <NUM_LIT> <EOL> sub . driver . print_convergence = False <EOL> sub . add ( '<STR_LIT>' , VarTree ( Globals ( ) , iotype = '<STR_LIT>' ) ) <EOL> sub . add ( '<STR_LIT>' , VarTree ( States ( ) , iotype = '<STR_LIT>' ) ) <EOL> sub . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sub . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sub . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sub . create_passthrough ( '<STR_LIT>' ) <EOL> sub . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sub . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . add ( '<STR_LIT>' , SLSQPdriver ( ) ) <EOL> self . driver . gradient_options . force_fd = True <EOL> self . add ( '<STR_LIT>' , Half ( ) ) <EOL> self . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> self . driver . add_parameter ( '<STR_LIT>' , low = <NUM_LIT:0.0> , high = <NUM_LIT> ) <EOL> self . driver . add_parameter ( '<STR_LIT>' , low = <NUM_LIT:0.0> , high = <NUM_LIT> ) <EOL> self . driver . add_objective ( '<STR_LIT>' ) <EOL> self . driver . add_constraint ( '<STR_LIT>' ) <EOL> self . driver . add_constraint ( '<STR_LIT>' ) <EOL> self . sub . globals . z1 = <NUM_LIT> <EOL> self . half . z2a = <NUM_LIT> <EOL> self . sub . x1 = <NUM_LIT:1.0> <EOL> def create_files ( ) : <EOL> """<STR_LIT>""" <EOL> prob = set_as_top ( SellarMDF ( ) ) <EOL> prob . recorders = [ HDF5CaseRecorder ( '<STR_LIT>' ) ] <EOL> prob . run ( ) <EOL> class TestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> try : <EOL> import h5py <EOL> except ImportError : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> from openmdao . lib . casehandlers . api import CaseDatasetHDF5 , HDF5CaseRecorder <EOL> path = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> self . cds = CaseDatasetHDF5 ( path , '<STR_LIT>' ) <EOL> self . startdir = os . getcwd ( ) <EOL> self . tempdir = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> os . chdir ( self . tempdir ) <EOL> def tearDown ( self ) : <EOL> self . cds = None <EOL> os . chdir ( self . startdir ) <EOL> if not os . environ . get ( '<STR_LIT>' , False ) : <EOL> try : <EOL> shutil . rmtree ( self . tempdir ) <EOL> except OSError : <EOL> pass <EOL> def test_query ( self ) : <EOL> vnames = self . cds . data . var_names ( ) . fetch ( ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( vnames , expected ) <EOL> cases = self . cds . data . fetch ( ) <EOL> self . assertEqual ( len ( cases ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( cases [ <NUM_LIT:0> ] ) , len ( expected ) ) <EOL> cases = self . cds . data . driver ( '<STR_LIT>' ) . fetch ( ) <EOL> self . assertEqual ( len ( cases ) , <NUM_LIT:10> ) <EOL> vnames = self . cds . data . driver ( '<STR_LIT>' ) . var_names ( ) . fetch ( ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( vnames , expected ) <EOL> names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> vnames = self . cds . data . vars ( names ) . var_names ( ) . fetch ( ) <EOL> self . assertEqual ( vnames , names ) <EOL> cases = self . cds . data . vars ( names ) . fetch ( ) <EOL> self . assertEqual ( len ( cases ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( cases [ <NUM_LIT:0> ] ) , len ( names ) ) <EOL> cases = self . cds . data . driver ( '<STR_LIT>' ) . vars ( '<STR_LIT>' ) . fetch ( ) <EOL> expected = [ [ <NUM_LIT:1.0> ] , [ <NUM_LIT:1.0> ] , [ - <NUM_LIT> ] , [ <NUM_LIT> ] , <EOL> [ - <NUM_LIT> ] , [ - <NUM_LIT> ] , [ - <NUM_LIT> ] , <EOL> [ - <NUM_LIT> ] , [ <NUM_LIT> ] , [ <NUM_LIT> ] ] <EOL> for exp , act in zip ( expected , cases ) : <EOL> self . assertAlmostEqual ( exp [ <NUM_LIT:0> ] , act [ <NUM_LIT:0> ] ) <EOL> cases = self . cds . data . driver ( '<STR_LIT>' ) . vars ( [ '<STR_LIT>' , '<STR_LIT>' ] ) . by_variable ( ) . fetch ( ) <EOL> expected = [ [ <NUM_LIT:1.0> , <NUM_LIT:1.0> , - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , <EOL> - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , <EOL> - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> ] ] <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> for exp , act in zip ( expected [ i ] , cases [ i ] ) : <EOL> self . assertAlmostEqual ( exp , act ) <EOL> cases = self . cds . data . driver ( '<STR_LIT>' ) . fetch ( ) <EOL> expected = [ <NUM_LIT> , <NUM_LIT> ] <EOL> actual = cases [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT:y>' ] <EOL> for exp , act in zip ( expected , actual ) : <EOL> self . assertAlmostEqual ( exp , act ) <EOL> cases = self . cds . data . case ( '<STR_LIT>' ) . fetch ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( cases ) ) <EOL> self . assertAlmostEqual ( cases [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> iteration_case_3_sub_5_expected = { <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> <EOL> } <EOL> for name , exp in iteration_case_3_sub_5_expected . items ( ) : <EOL> self . assertAlmostEqual ( exp , cases [ <NUM_LIT:0> ] [ name ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
