How to use test_finalizer method in green

Best Python code snippet using green

composers_test.py

Source:composers_test.py Github

copy

Full Screen

...69 empty_at_server())70 return client_works.ClientWorkProcess(empty_init_fn, next_fn)71def test_aggregator():72 return mean.MeanFactory().create(FLOAT_TYPE, FLOAT_TYPE)73def test_finalizer():74 @computations.federated_computation(75 empty_init_fn.type_signature.result,76 computation_types.at_server(MODEL_WEIGHTS_TYPE),77 computation_types.at_server(FLOAT_TYPE))78 def next_fn(state, weights, updates):79 new_weights = intrinsics.federated_map(80 computations.tf_computation(lambda x, y: x + y),81 (weights.trainable, updates))82 new_weights = intrinsics.federated_zip(83 model_utils.ModelWeights(new_weights, ()))84 return measured_process.MeasuredProcessOutput(state, new_weights,85 empty_at_server())86 return finalizers.FinalizerProcess(empty_init_fn, next_fn)87class ComposeLearningProcessTest(test_case.TestCase):88 def test_learning_process_composes(self):89 process = composers.compose_learning_process(test_init_model_weights_fn,90 test_distributor(),91 test_client_work(),92 test_aggregator(),93 test_finalizer())94 self.assertIsInstance(process, learning_process.LearningProcess)95 self.assertEqual(96 process.initialize.type_signature.result.member.python_container,97 composers.LearningAlgorithmState)98 self.assertEqual(99 process.initialize.type_signature.result.member.global_model_weights,100 MODEL_WEIGHTS_TYPE)101 # Reported metrics have the expected fields.102 metrics_type = process.next.type_signature.result.metrics.member103 self.assertTrue(structure.has_field(metrics_type, 'distributor'))104 self.assertTrue(structure.has_field(metrics_type, 'client_work'))105 self.assertTrue(structure.has_field(metrics_type, 'aggregator'))106 self.assertTrue(structure.has_field(metrics_type, 'finalizer'))107 self.assertLen(metrics_type, 4)108 def test_one_arg_computation_init_raises(self):109 @computations.tf_computation(computation_types.TensorType(tf.float32))110 def init_model_weights_fn(x):111 return model_utils.ModelWeights(trainable=x, non_trainable=())112 with self.assertRaisesRegex(TypeError, 'Computation'):113 composers.compose_learning_process(init_model_weights_fn,114 test_distributor(), test_client_work(),115 test_aggregator(), test_finalizer())116 def test_not_tff_computation_init_raises(self):117 def init_model_weights_fn():118 return model_utils.ModelWeights(119 trainable=tf.constant(1.0), non_trainable=())120 with self.assertRaisesRegex(TypeError, 'Computation'):121 composers.compose_learning_process(init_model_weights_fn,122 test_distributor(), test_client_work(),123 test_aggregator(), test_finalizer())124 def test_federated_init_raises(self):125 @computations.federated_computation()126 def init_model_weights_fn():127 return intrinsics.federated_eval(test_init_model_weights_fn,128 placements.SERVER)129 with self.assertRaisesRegex(TypeError, 'unplaced'):130 composers.compose_learning_process(init_model_weights_fn,131 test_distributor(), test_client_work(),132 test_aggregator(), test_finalizer())133 def test_not_model_weights_init_raises(self):134 @computations.tf_computation()135 def init_model_weights_fn():136 return collections.OrderedDict(137 trainable=tf.constant(1.0), non_trainable=())138 with self.assertRaisesRegex(TypeError, 'ModelWeights'):139 composers.compose_learning_process(init_model_weights_fn,140 test_distributor(), test_client_work(),141 test_aggregator(), test_finalizer())142 def test_not_distributor_type_raises(self):143 distributor = test_distributor()144 bad_distributor = measured_process.MeasuredProcess(distributor.initialize,145 distributor.next)146 with self.assertRaisesRegex(TypeError, 'DistributionProcess'):147 composers.compose_learning_process(test_init_model_weights_fn,148 bad_distributor, test_client_work(),149 test_aggregator(), test_finalizer())150 def test_not_client_work_type_raises(self):151 client_work = test_client_work()152 bad_client_work = measured_process.MeasuredProcess(client_work.initialize,153 client_work.next)154 with self.assertRaisesRegex(TypeError, 'ClientWorkProcess'):155 composers.compose_learning_process(test_init_model_weights_fn,156 test_distributor(), bad_client_work,157 test_aggregator(), test_finalizer())158 def test_not_aggregator_type_raises(self):159 aggregator = test_aggregator()160 bad_aggregator = measured_process.MeasuredProcess(aggregator.initialize,161 aggregator.next)162 with self.assertRaisesRegex(TypeError, 'AggregationProcess'):163 composers.compose_learning_process(test_init_model_weights_fn,164 test_distributor(), test_client_work(),165 bad_aggregator, test_finalizer())166 def test_unweighted_aggregator_raises(self):167 bad_aggregator = sum_factory.SumFactory().create(FLOAT_TYPE)168 with self.assertRaisesRegex(TypeError, 'weighted'):169 composers.compose_learning_process(test_init_model_weights_fn,170 test_distributor(), test_client_work(),171 bad_aggregator, test_finalizer())172 def test_not_finalizer_type_raises(self):173 finalizer = test_finalizer()174 bad_finalizer = measured_process.MeasuredProcess(finalizer.initialize,175 finalizer.next)176 with self.assertRaisesRegex(TypeError, 'FinalizerProcess'):177 composers.compose_learning_process(test_init_model_weights_fn,178 test_distributor(), test_client_work(),179 test_aggregator(), bad_finalizer)180 # TODO(b/190334722): Add more tests that assert early errors are raised in the181 # _validate_args method, when adding custom error messages.182class VanillaFedAvgTest(test_case.TestCase, parameterized.TestCase):183 def _test_data(self):184 return tf.data.Dataset.from_tensor_slices(185 collections.OrderedDict(186 x=[[1.0, 2.0], [3.0, 4.0]],187 y=[[5.0], [6.0]],...

Full Screen

Full Screen

test_gc.py

Source:test_gc.py Github

copy

Full Screen

...63 gc.collect()64 del a65 if gc.collect() == 0:66 raise TestFailed67def test_finalizer():68 # A() is uncollectable if it is part of a cycle, make sure it shows up69 # in gc.garbage.70 class A:71 def __del__(self): pass72 class B:73 pass74 a = A()75 a.a = a76 id_a = id(a)77 b = B()78 b.b = b79 gc.collect()80 del a81 del b...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run green automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful