Exemple #1
0
    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.append(PassK_check_fixed_point_property())
        self.passmanager.append([
            PassK_check_fixed_point_property(),
            PassA_TP_NR_NP(),
            PassF_reduce_dag_property()
        ],
                                do_while=lambda property_set: not property_set[
                                    'property_fixed_point'],
                                condition=lambda property_set:
                                not property_set['property_fixed_point'])
        self.assertScheduler(self.circuit, 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'
        ])
Exemple #2
0
 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.append([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_control_flow_plugin(self):
     """ Dump passes in a custom flow controller. """
     passmanager = PassManager()
     FlowController.add_flow_controller('do_x_times', DoXTimesController)
     passmanager.append(
         [PassB_TP_RA_PA(), PassC_TP_RA_PA()], do_x_times=lambda x: 3)
     self.assertPassLog(passmanager, [
         'PassA_TP_NR_NP', 'PassB_TP_RA_PA', 'PassC_TP_RA_PA',
         'PassB_TP_RA_PA', 'PassC_TP_RA_PA', 'PassB_TP_RA_PA',
         'PassC_TP_RA_PA'
     ])
Exemple #4
0
    def test_control_flow_plugin(self):
        """Dump passes in a custom flow controller."""
        passmanager = PassManager()
        FlowController.add_flow_controller('do_x_times', DoXTimesController)
        passmanager.append([PassB_TP_RA_PA(), PassC_TP_RA_PA()],
                           do_x_times=lambda x: 3)

        expected = [{'options': {'max_iteration': 1000},
                     'passes': [PassB_TP_RA_PA(),
                                PassC_TP_RA_PA()],
                     'type': DoXTimesController}]
        self.assertEqual(expected, passmanager.passes())
Exemple #5
0
 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.append([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)