def test_loop_and_conditional(self):
        """ Run a loop first, then a conditional"""
        FlowController.remove_flow_controller('condition')
        FlowController.add_flow_controller('condition', ConditionalController)

        self.passmanager.add_passes(PassK_check_fixed_point_property())
        self.passmanager.add_passes(
            [
                PassK_check_fixed_point_property(),
                PassA_TP_NR_NP(),
                PassF_reduce_dag_property()
            ],
            do_while=lambda property_set: not property_set['fixed_point'][
                'property'],
            condition=lambda property_set: not property_set['fixed_point'][
                'property'])
        self.assertScheduler(self.dag, self.passmanager, [
            'run analysis pass PassG_calculates_dag_property',
            'set property as 8 (from dag.property)',
            'run analysis pass PassK_check_fixed_point_property',
            'run transformation pass PassA_TP_NR_NP',
            'run transformation pass PassF_reduce_dag_property',
            'dag property = 6',
            'run analysis pass PassG_calculates_dag_property',
            'set property as 6 (from dag.property)',
            'run analysis pass PassK_check_fixed_point_property',
            'run transformation pass PassA_TP_NR_NP',
            'run transformation pass PassF_reduce_dag_property',
            'dag property = 5',
            'run analysis pass PassG_calculates_dag_property',
            'set property as 5 (from dag.property)',
            'run analysis pass PassK_check_fixed_point_property',
            'run transformation pass PassA_TP_NR_NP',
            'run transformation pass PassF_reduce_dag_property',
            'dag property = 4',
            'run analysis pass PassG_calculates_dag_property',
            'set property as 4 (from dag.property)',
            'run analysis pass PassK_check_fixed_point_property',
            'run transformation pass PassA_TP_NR_NP',
            'run transformation pass PassF_reduce_dag_property',
            'dag property = 3',
            'run analysis pass PassG_calculates_dag_property',
            'set property as 3 (from dag.property)',
            'run analysis pass PassK_check_fixed_point_property',
            'run transformation pass PassA_TP_NR_NP',
            'run transformation pass PassF_reduce_dag_property',
            'dag property = 2',
            'run analysis pass PassG_calculates_dag_property',
            'set property as 2 (from dag.property)',
            'run analysis pass PassK_check_fixed_point_property',
            'run transformation pass PassA_TP_NR_NP',
            'run transformation pass PassF_reduce_dag_property',
            'dag property = 2',
            'run analysis pass PassG_calculates_dag_property',
            'set property as 2 (from dag.property)',
            'run analysis pass PassK_check_fixed_point_property',
            'run transformation pass PassA_TP_NR_NP',
            'run transformation pass PassF_reduce_dag_property',
            'dag property = 2'
        ])
 def test_control_flow_plugin(self):
     """ Adds a control flow plugin with a single parameter and runs it. """
     FlowController.add_flow_controller('do_x_times', DoXTimesController)
     self.passmanager.add_passes([PassB_TP_RA_PA(), PassC_TP_RA_PA()], do_x_times=lambda x: 3)
     self.assertScheduler(self.dag, self.passmanager, ['run transformation pass PassA_TP_NR_NP',
                                                       'run transformation pass PassB_TP_RA_PA',
                                                       'run transformation pass PassC_TP_RA_PA',
                                                       'run transformation pass PassB_TP_RA_PA',
                                                       'run transformation pass PassC_TP_RA_PA',
                                                       'run transformation pass PassB_TP_RA_PA',
                                                       'run transformation pass PassC_TP_RA_PA'])
 def test_callable_control_flow_plugin(self):
     """ Removes do_while, then adds it back. Checks max_iteration still working. """
     controllers_length = len(FlowController.registered_controllers)
     FlowController.remove_flow_controller('do_while')
     self.assertEqual(controllers_length - 1, len(FlowController.registered_controllers))
     FlowController.add_flow_controller('do_while', DoWhileController)
     self.assertEqual(controllers_length, len(FlowController.registered_controllers))
     self.passmanager.add_passes([PassB_TP_RA_PA(), PassC_TP_RA_PA()],
                                 do_while=lambda property_set: True, max_iteration=2)
     self.assertSchedulerRaises(self.dag, self.passmanager,
                                ['run transformation pass PassA_TP_NR_NP',
                                 'run transformation pass PassB_TP_RA_PA',
                                 'run transformation pass PassC_TP_RA_PA',
                                 'run transformation pass PassB_TP_RA_PA',
                                 'run transformation pass PassC_TP_RA_PA'], TranspilerError)