Skip to content

Commit

Permalink
Merge pull request #969 from Kenneth-T-Moore/ken1
Browse files Browse the repository at this point in the history
Change examples to use "import openmdao.api as om".
  • Loading branch information
swryan committed Jun 19, 2019
2 parents 8e24a9e + 9a380cd commit 54004c1
Show file tree
Hide file tree
Showing 168 changed files with 7,806 additions and 7,514 deletions.
20 changes: 10 additions & 10 deletions benchmark/benchmark_beam.py
Expand Up @@ -3,7 +3,7 @@
"""
import unittest

from openmdao.api import Problem
import openmdao.api as om
from openmdao.test_suite.test_examples.beam_optimization.multipoint_beam_group import MultipointBeamGroup


Expand All @@ -22,9 +22,9 @@ def benchmark_beam_np1(self):
num_cp = 4
num_load_cases = 32

prob = Problem(model=MultipointBeamGroup(E=E, L=L, b=b, volume=volume,
num_elements=num_elements, num_cp=num_cp,
num_load_cases=num_load_cases))
prob = om.Problem(model=MultipointBeamGroup(E=E, L=L, b=b, volume=volume,
num_elements=num_elements, num_cp=num_cp,
num_load_cases=num_load_cases))

prob.setup()

Expand All @@ -46,9 +46,9 @@ def benchmark_beam_np2(self):
num_cp = 4
num_load_cases = 32

prob = Problem(model=MultipointBeamGroup(E=E, L=L, b=b, volume=volume,
num_elements=num_elements, num_cp=num_cp,
num_load_cases=num_load_cases))
prob = om.Problem(model=MultipointBeamGroup(E=E, L=L, b=b, volume=volume,
num_elements=num_elements, num_cp=num_cp,
num_load_cases=num_load_cases))

prob.setup()

Expand All @@ -71,9 +71,9 @@ def benchmark_beam_np4(self):
num_cp = 4
num_load_cases = 32

prob = Problem(model=MultipointBeamGroup(E=E, L=L, b=b, volume=volume,
num_elements=num_elements, num_cp=num_cp,
num_load_cases=num_load_cases))
prob = om.Problem(model=MultipointBeamGroup(E=E, L=L, b=b, volume=volume,
num_elements=num_elements, num_cp=num_cp,
num_load_cases=num_load_cases))

prob.setup()

Expand Down
14 changes: 7 additions & 7 deletions benchmark/benchmark_manycomps.py
@@ -1,27 +1,27 @@

import unittest

from openmdao.api import Problem, Group
import openmdao.api as om
from openmdao.test_suite.build4test import DynComp, create_dyncomps


class BM(unittest.TestCase):
"""Setup of models with lots of components"""

def benchmark_100(self):
p = Problem()
p = om.Problem()
create_dyncomps(p.model, 100, 10, 10, 5)
p.setup(check=False)
p.setup()
p.final_setup()

def benchmark_500(self):
p = Problem()
p = om.Problem()
create_dyncomps(p.model, 500, 10, 10, 5)
p.setup(check=False)
p.setup()
p.final_setup()

def benchmark_1K(self):
p = Problem()
p = om.Problem()
create_dyncomps(p.model, 1000, 10, 10, 5)
p.setup(check=False)
p.setup()
p.final_setup()
18 changes: 9 additions & 9 deletions benchmark/benchmark_manyvars.py
@@ -1,12 +1,12 @@

import unittest

from openmdao.api import Problem, Group
import openmdao.api as om
from openmdao.test_suite.build4test import DynComp, create_dyncomps


def _build_comp(np, no, ns=0):
prob = Problem()
prob = om.Problem()
prob.model.add_subsystem("C1", DynComp(np, no, ns))
return prob

Expand All @@ -18,36 +18,36 @@ class BM(unittest.TestCase):

def benchmark_1Kparams(self):
prob = _build_comp(1000, 1)
prob.setup(check=False)
prob.setup()
prob.final_setup()

def benchmark_2Kparams(self):
prob = _build_comp(2000, 1)
prob.setup(check=False)
prob.setup()
prob.final_setup()

def benchmark_1Kouts(self):
prob = _build_comp(1, 1000)
prob.setup(check=False)
prob.setup()
prob.final_setup()

def benchmark_2Kouts(self):
prob = _build_comp(1, 2000)
prob.setup(check=False)
prob.setup()
prob.final_setup()

def benchmark_1Kvars(self):
prob = _build_comp(500, 500)
prob.setup(check=False)
prob.setup()
prob.final_setup()

def benchmark_2Kvars(self):
prob = _build_comp(1000, 1000)
prob.setup(check=False)
prob.setup()
prob.final_setup()


if __name__ == '__main__':
prob = _build_comp(1, 2000)
prob.setup(check=False)
prob.setup()
prob.final_setup()
24 changes: 15 additions & 9 deletions benchmark/benchmark_multipoint.py
@@ -1,13 +1,14 @@
from __future__ import print_function
import time
import unittest
from six.moves import range

import numpy as np

import time
from openmdao.api import Problem, Group, ExplicitComponent, IndepVarComp, ExecComp
import openmdao.api as om


class Plus(ExplicitComponent):
class Plus(om.ExplicitComponent):
def __init__(self, adder):
super(Plus, self).__init__()
self.adder = float(adder)
Expand All @@ -19,7 +20,8 @@ def setup(self):
def compute(self, inputs, outputs):
outputs['f1'] = inputs['x'] + self.adder

class Times(ExplicitComponent):

class Times(om.ExplicitComponent):
def __init__(self, scalar):
super(Times, self).__init__()
self.scalar = float(scalar)
Expand All @@ -31,7 +33,8 @@ def setup(self):
def compute(self, inputs, outputs):
outputs['f2'] = inputs['f1'] + self.scalar

class Point(Group):

class Point(om.Group):

def __init__(self, adder, scalar):
super(Point, self).__init__()
Expand All @@ -42,7 +45,8 @@ def setup(self):
self.add_subsystem('plus', Plus(self.adder), promotes=['*'])
self.add_subsystem('times', Times(self.scalar), promotes=['*'])

class Summer(ExplicitComponent):

class Summer(om.ExplicitComponent):

def __init__(self, size):
super(Summer, self).__init__()
Expand All @@ -60,7 +64,8 @@ def compute(self, inputs, outputs):
tot += inputs['y%d'%i]
outputs['total'] = tot

class MultiPoint(Group):

class MultiPoint(om.Group):

def __init__(self, adders, scalars):
super(MultiPoint, self).__init__()
Expand All @@ -78,6 +83,7 @@ def setup(self):

self.add_subsystem('aggregate', Summer(size))


class BM(unittest.TestCase):
"""A few 'brute force' multipoint cases (1K, 2K, 5K)"""

Expand All @@ -87,8 +93,8 @@ def _setup_bm(self, npts):
adders = np.random.random(size)
scalars = np.random.random(size)

prob = Problem(MultiPoint(adders, scalars))
prob.setup(check=False)
prob = om.Problem(MultiPoint(adders, scalars))
prob.setup()

return prob

Expand Down
22 changes: 11 additions & 11 deletions benchmark/benchmark_parallel_GA.py
Expand Up @@ -4,7 +4,7 @@
from time import time
import unittest

from openmdao.api import Problem, SimpleGADriver, IndepVarComp, Group
import openmdao.api as om
from openmdao.test_suite.components.exec_comp_for_test import ExecComp4Test


Expand All @@ -15,13 +15,13 @@
POPSIZE = 40


class GAGroup(Group):
class GAGroup(om.Group):

def setup(self):

self.add_subsystem('p1', IndepVarComp('x', 1.0))
self.add_subsystem('p2', IndepVarComp('y', 1.0))
self.add_subsystem('p3', IndepVarComp('z', 1.0))
self.add_subsystem('p1', om.IndepVarComp('x', 1.0))
self.add_subsystem('p2', om.IndepVarComp('y', 1.0))
self.add_subsystem('p3', om.IndepVarComp('z', 1.0))

self.add_subsystem('comp', ExecComp4Test(['f = x + y + z'], nl_delay=DELAY))

Expand All @@ -37,10 +37,10 @@ class BenchParGA1(unittest.TestCase):

def benchmark_genetic_1(self):

prob = Problem()
prob = om.Problem()
prob.model = GAGroup()

driver = prob.driver = SimpleGADriver()
driver = prob.driver = om.SimpleGADriver()
driver.options['max_gen'] = MAXGEN
driver.options['pop_size'] = POPSIZE
driver.options['run_parallel'] = True
Expand All @@ -58,10 +58,10 @@ class BenchParGA2(unittest.TestCase):

def benchmark_genetic_2(self):

prob = Problem()
prob = om.Problem()
prob.model = GAGroup()

driver = prob.driver = SimpleGADriver()
driver = prob.driver = om.SimpleGADriver()
driver.options['max_gen'] = MAXGEN
driver.options['pop_size'] = POPSIZE
driver.options['run_parallel'] = True
Expand All @@ -79,10 +79,10 @@ class BenchParGA4(unittest.TestCase):

def benchmark_genetic_4(self):

prob = Problem()
prob = om.Problem()
prob.model = GAGroup()

driver = prob.driver = SimpleGADriver()
driver = prob.driver = om.SimpleGADriver()
driver.options['max_gen'] = MAXGEN
driver.options['pop_size'] = POPSIZE
driver.options['run_parallel'] = True
Expand Down
13 changes: 6 additions & 7 deletions benchmark/benchmark_param_cycle.py
@@ -1,13 +1,12 @@

import unittest

from openmdao.api import Problem, Group, NewtonSolver, ScipyKrylov, NonlinearBlockGS, \
LinearBlockGS, DirectSolver
import openmdao.api as om
from openmdao.test_suite.parametric_suite import ParameterizedInstance
from openmdao.utils.assert_utils import assert_rel_error


def _build(solver_class=NewtonSolver, linear_solver_class=ScipyKrylov,
def _build(solver_class=om.NewtonSolver, linear_solver_class=om.ScipyKrylov,
solver_options=None, linear_solver_options=None, **options):
suite = ParameterizedInstance('cycle', **options)
suite.solver_class = solver_class
Expand Down Expand Up @@ -44,7 +43,7 @@ class BM(unittest.TestCase):

def benchmark_comp200_var5_nlbs_lbgs(self):
suite = _build(
solver_class=NonlinearBlockGS, linear_solver_class=LinearBlockGS,
solver_class=om.NonlinearBlockGS, linear_solver_class=om.LinearBlockGS,
assembled_jac=False,
jacobian_type='dense',
connection_type='explicit',
Expand All @@ -58,7 +57,7 @@ def benchmark_comp200_var5_nlbs_lbgs(self):

def benchmark_comp200_var5_newton_lings(self):
suite = _build(
solver_class=NewtonSolver, linear_solver_class=LinearBlockGS,
solver_class=om.NewtonSolver, linear_solver_class=om.LinearBlockGS,
solver_options={'maxiter': 20},
linear_solver_options={'maxiter': 200, 'atol': 1e-10, 'rtol': 1e-10},
assembled_jac=False,
Expand All @@ -74,7 +73,7 @@ def benchmark_comp200_var5_newton_lings(self):

def benchmark_comp200_var5_newton_direct_assembled(self):
suite = _build(
solver_class=NewtonSolver, linear_solver_class=DirectSolver,
solver_class=om.NewtonSolver, linear_solver_class=om.DirectSolver,
linear_solver_options={}, # defaults not valid for DirectSolver
assembled_jac=True,
jacobian_type='dense',
Expand All @@ -89,7 +88,7 @@ def benchmark_comp200_var5_newton_direct_assembled(self):

def benchmark_comp50_var5_newton_direct_assembled_fd(self):
suite = _build(
solver_class=NewtonSolver, linear_solver_class=DirectSolver,
solver_class=om.NewtonSolver, linear_solver_class=om.DirectSolver,
linear_solver_options={}, # defaults not valid for DirectSolver
assembled_jac=True,
jacobian_type='dense',
Expand Down
14 changes: 7 additions & 7 deletions benchmark/benchmark_trees.py
@@ -1,30 +1,30 @@

import unittest

from openmdao.api import Problem, Group
import openmdao.api as om
from openmdao.test_suite.build4test import DynComp, create_dyncomps, make_subtree


class BM(unittest.TestCase):
"""Setup of models with various tree structures"""

def benchmark_L4_sub2_c10(self):
p = Problem()
p = om.Problem()
make_subtree(p.model, nsubgroups=2, levels=4, ncomps=10,
ninputs=10, noutputs=10, nconns=5)
p.setup(check=False)
p.setup()
p.final_setup()

def benchmark_L6_sub2_c10(self):
p = Problem()
p = om.Problem()
make_subtree(p.model, nsubgroups=2, levels=6, ncomps=10,
ninputs=10, noutputs=10, nconns=5)
p.setup(check=False)
p.setup()
p.final_setup()

def benchmark_L7_sub2_c10(self):
p = Problem()
p = om.Problem()
make_subtree(p.model, nsubgroups=2, levels=7, ncomps=10,
ninputs=10, noutputs=10, nconns=5)
p.setup(check=False)
p.setup()
p.final_setup()
8 changes: 5 additions & 3 deletions openmdao/components/add_subtract_comp.py
@@ -1,9 +1,11 @@
"""Definition of the Add/Subtract Component."""

"""
Definition of the Add/Subtract Component.
"""
import collections
from six import string_types

import numpy as np
from scipy import sparse as sp
from six import string_types

from openmdao.core.explicitcomponent import ExplicitComponent

Expand Down

0 comments on commit 54004c1

Please sign in to comment.