def configure(self):
                """Adds the Genetic driver to the assembly"""

                self.add('driver',Genetic())
                self.add('comp',SomeComp())
                self.driver.workflow.add('comp')

                self.driver.add_parameter('comp.z')
            def configure(self):
                """Adds the Genetic driver to the assembly"""

                opt = self.add('optimizer',Genetic())
                self.add('comp',SomeComp())
                opt.workflow.add('comp')

                self.optimizer.add_parameter('comp.x')
                self.optimizer.add_parameter('comp.y')
                self.optimizer.add_parameter('comp.z')
            def __init__(self):
                """Adds the Genetic driver to the assembly"""

                super(Simulation, self).__init__()

                self.add('driver', Genetic())
                self.add('comp', SomeComp())
                self.driver.workflow.add('comp')

                self.driver.add_parameter('comp.z')
    def setUp(self):
        random.seed(10)

        # pyevolve does some caching that causes failures during our
        # complete unit tests due to stale values in the cache attributes
        # below, so reset them here
        Selectors.GRankSelector.cachePopID = None
        Selectors.GRankSelector.cacheCount = None
        Selectors.GRouletteWheel.cachePopID = None
        Selectors.GRouletteWheel.cacheWheel = None

        self.top = set_as_top(Assembly())
        self.top.add('driver', Genetic())
        self.top.driver.seed = 123
    def test_initial_run(self):

        from openmdao.main.interfaces import IHasParameters, implements
        from openmdao.main.hasparameters import HasParameters
        from openmdao.util.decorators import add_delegate

        class MyComp(Component):

            x = Float(0.0, iotype='in', low=-10, high=10)
            xx = Float(0.0, iotype='in', low=-10, high=10)
            f_x = Float(iotype='out')
            y = Float(iotype='out')

            def execute(self):
                if self.xx != 1.0:
                    self.raise_exception("Lazy", RuntimeError)
                self.f_x = 2.0*self.x
                self.y = self.x

                print self.x, self.xx, self.f_x, self.y

        @add_delegate(HasParameters)
        class SpecialDriver(Driver):

            implements(IHasParameters)

            def execute(self):
                self.set_parameters([1.0])

        top = set_as_top(Assembly())
        top.add('comp', MyComp())
        top.add('driver', Genetic())
        top.add('subdriver', SpecialDriver())
        top.driver.workflow.add('subdriver')
        top.subdriver.workflow.add('comp')

        top.subdriver.add_parameter('comp.xx')
        top.driver.add_parameter('comp.x')
        top.driver.add_objective('comp.f_x')

        top.run()