def test_conditional_and_loop(self): """Dump passes with a conditional and a loop.""" passmanager = PassManager() passmanager.append(PassE_AP_NR_NP(True)) 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: property_set[ 'property_fixed_point']) expected = [{ 'options': { 'max_iteration': 1000 }, 'passes': [PassE_AP_NR_NP(True)], 'type': FlowControllerLinear }, { 'options': { 'max_iteration': 1000 }, 'passes': [ PassK_check_fixed_point_property(), PassA_TP_NR_NP(), PassF_reduce_dag_property() ], 'type': ConditionalController }] self.assertEqual(expected, passmanager.passes())
def test_passes_in_linear(self): """Dump passes in the same FlowControllerLinear""" passmanager = PassManager(passes=[ PassC_TP_RA_PA(), PassB_TP_RA_PA(), PassD_TP_NR_NP(argument1=[1, 2]), PassB_TP_RA_PA() ]) expected = [{ 'options': { 'ignore_preserves': False, 'ignore_requires': False, 'max_iteration': 1000 }, 'passes': [ PassC_TP_RA_PA(), PassB_TP_RA_PA(), PassD_TP_NR_NP(argument1=[1, 2]), PassB_TP_RA_PA() ], 'type': FlowControllerLinear }] self.assertEqual(expected, passmanager.passes())
def test_conditional_and_loop(self): """Dump passes with a conditional and a loop.""" passmanager = PassManager() passmanager.append(PassE_AP_NR_NP(True)) 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: property_set[ 'property_fixed_point']) expected = [{ 'passes': [PassE_AP_NR_NP(True)], 'flow_controllers': {} }, { 'passes': [ PassK_check_fixed_point_property(), PassA_TP_NR_NP(), PassF_reduce_dag_property() ], 'flow_controllers': {'condition', 'do_while'} }] self.assertEqual(expected, passmanager.passes())
def test_passes(self): """Dump passes in different FlowControllerLinear""" passmanager = PassManager() passmanager.append(PassC_TP_RA_PA()) passmanager.append(PassB_TP_RA_PA()) expected = [{'flow_controllers': {}, 'passes': [PassC_TP_RA_PA()]}, {'flow_controllers': {}, 'passes': [PassB_TP_RA_PA()]}] self.assertEqual(expected, passmanager.passes())
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 = [{'passes': [PassB_TP_RA_PA(), PassC_TP_RA_PA()], 'flow_controllers': {'do_x_times'}}] self.assertEqual(expected, passmanager.passes())
def test_passes_in_linear(self): """Dump passes in the same FlowControllerLinear""" passmanager = PassManager(passes=[ PassC_TP_RA_PA(), PassB_TP_RA_PA(), PassD_TP_NR_NP(argument1=[1, 2]), PassB_TP_RA_PA()]) expected = [{'flow_controllers': {}, 'passes': [PassC_TP_RA_PA(), PassB_TP_RA_PA(), PassD_TP_NR_NP(argument1=[1, 2]), PassB_TP_RA_PA()]}] self.assertEqual(expected, passmanager.passes())
def test_passes(self): """Dump passes in different FlowControllerLinear""" passmanager = PassManager() passmanager.append(PassC_TP_RA_PA()) passmanager.append(PassB_TP_RA_PA()) expected = [{'options': {'max_iteration': 1000}, 'passes': [PassC_TP_RA_PA()], 'type': FlowControllerLinear}, {'options': {'max_iteration': 1000}, 'passes': [PassB_TP_RA_PA()], 'type': FlowControllerLinear}] self.assertEqual(expected, passmanager.passes())
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': { 'ignore_preserves': False, 'ignore_requires': False, 'max_iteration': 1000 }, 'passes': [PassB_TP_RA_PA(), PassC_TP_RA_PA()], 'type': DoXTimesController }] self.assertEqual(expected, passmanager.passes())
def test_repeated_stages(self): stages = ["alpha", "omega", "alpha"] pre_alpha = PassManager(Unroller(["u", "cx"])) alpha = PassManager(Depth()) post_alpha = PassManager(BasicSwap([[0, 1], [1, 2]])) omega = PassManager(Optimize1qGates()) spm = StagedPassManager(stages, pre_alpha=pre_alpha, alpha=alpha, post_alpha=post_alpha, omega=omega) passes = [ *pre_alpha.passes(), *alpha.passes(), *post_alpha.passes(), *omega.passes(), *pre_alpha.passes(), *alpha.passes(), *post_alpha.passes(), ] self.assertEqual(spm.passes(), passes)