How to use _setup_session method in Molotov

Best Python code snippet using molotov_python

sparse_utils_test.py

Source: sparse_utils_test.py Github

copy

Full Screen

...21import numpy as np22from rigl import sparse_utils23import tensorflow as tf24class GetMaskRandomTest(tf.test.TestCase, parameterized.TestCase):25 def _setup_session(self):26 """Resets the graph and returns a fresh session."""27 tf.reset_default_graph()28 sess = tf.Session()29 return sess30 @parameterized.parameters(((30, 40), 0.5), ((1, 2, 1, 4), 0.8), ((3,), 0.1))31 def testMaskConnectionDeterminism(self, shape, sparsity):32 sess = self._setup_session()33 mask = tf.ones(shape)34 mask1 = sparse_utils.get_mask_random(mask, sparsity, tf.int32)35 mask2 = sparse_utils.get_mask_random(mask, sparsity, tf.int32)36 mask1_array, = sess.run([mask1])37 mask2_array, = sess.run([mask2])38 self.assertEqual(np.sum(mask1_array), np.sum(mask2_array))39 @parameterized.parameters(((30, 4), 0.5, 60), ((1, 2, 1, 4), 0.8, 1),40 ((30,), 0.1, 27))41 def testMaskFraction(self, shape, sparsity, expected_ones):42 sess = self._setup_session()43 mask = tf.ones(shape)44 mask1 = sparse_utils.get_mask_random(mask, sparsity, tf.int32)45 mask1_array, = sess.run([mask1])46 self.assertEqual(np.sum(mask1_array), expected_ones)47 @parameterized.parameters(tf.int32, tf.float32, tf.int64, tf.float64)48 def testMaskDtype(self, dtype):49 _ = self._setup_session()50 mask = tf.ones((3, 2))51 mask1 = sparse_utils.get_mask_random(mask, 0.5, dtype)52 self.assertEqual(mask1.dtype, dtype)53class GetSparsitiesTest(tf.test.TestCase, parameterized.TestCase):54 def _setup_session(self):55 """Resets the graph and returns a fresh session."""56 tf.reset_default_graph()57 sess = tf.Session()58 return sess59 @parameterized.parameters(0., 0.4, 0.9)60 def testSparsityDictRandom(self, default_sparsity):61 _ = self._setup_session()62 all_masks = [tf.get_variable(shape=(2, 3), name='var1/​mask'),63 tf.get_variable(shape=(2, 3), name='var2/​mask'),64 tf.get_variable(shape=(1, 1, 3), name='var3/​mask')]65 custom_sparsity = {'var1': 0.8}66 sparsities = sparse_utils.get_sparsities(67 all_masks, 'random', default_sparsity, custom_sparsity)68 self.assertEqual(sparsities[all_masks[0].name], 0.8)69 self.assertEqual(sparsities[all_masks[1].name], default_sparsity)70 self.assertEqual(sparsities[all_masks[2].name], default_sparsity)71 @parameterized.parameters(0.1, 0.4, 0.9)72 def testSparsityDictErdosRenyiCustom(self, default_sparsity):73 _ = self._setup_session()74 all_masks = [tf.get_variable(shape=(2, 4), name='var1/​mask'),75 tf.get_variable(shape=(2, 3), name='var2/​mask'),76 tf.get_variable(shape=(1, 1, 3), name='var3/​mask')]77 custom_sparsity = {'var3': 0.8}78 sparsities = sparse_utils.get_sparsities(79 all_masks, 'erdos_renyi', default_sparsity, custom_sparsity)80 self.assertEqual(sparsities[all_masks[2].name], 0.8)81 @parameterized.parameters(0.1, 0.4, 0.9)82 def testSparsityDictErdosRenyiError(self, default_sparsity):83 _ = self._setup_session()84 all_masks = [tf.get_variable(shape=(2, 4), name='var1/​mask'),85 tf.get_variable(shape=(2, 3), name='var2/​mask'),86 tf.get_variable(shape=(1, 1, 3), name='var3/​mask')]87 custom_sparsity = {'var3': 0.8}88 sparsities = sparse_utils.get_sparsities(89 all_masks, 'erdos_renyi', default_sparsity, custom_sparsity)90 self.assertEqual(sparsities[all_masks[2].name], 0.8)91 @parameterized.parameters(((2, 3), (2, 3), 0.5),92 ((1, 1, 2, 3), (1, 1, 2, 3), 0.3),93 ((8, 6), (4, 3), 0.7),94 ((80, 4), (20, 20), 0.8),95 ((2, 6), (2, 3), 0.8))96 def testSparsityDictErdosRenyiSparsitiesScale(97 self, shape1, shape2, default_sparsity):98 _ = self._setup_session()99 all_masks = [tf.get_variable(shape=shape1, name='var1/​mask'),100 tf.get_variable(shape=shape2, name='var2/​mask')]101 custom_sparsity = {}102 sparsities = sparse_utils.get_sparsities(103 all_masks, 'erdos_renyi', default_sparsity, custom_sparsity)104 sparsity1 = sparsities[all_masks[0].name]105 size1 = np.prod(shape1)106 sparsity2 = sparsities[all_masks[1].name]107 size2 = np.prod(shape2)108 # Ensure that total number of connections are similar.109 expected_zeros_uniform = (110 sparse_utils.get_n_zeros(size1, default_sparsity) +111 sparse_utils.get_n_zeros(size2, default_sparsity))112 # Ensure that total number of connections are similar....

Full Screen

Full Screen

session.py

Source: session.py Github

copy

Full Screen

...10 fernet_key = fernet.Fernet.generate_key()11 secret_key = base64.urlsafe_b64decode(fernet_key)12 app['config']['SECRET_KEY'] = secret_key13 storage = EncryptedCookieStorage(secret_key, cookie_name='API_SESSION')...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

How to increase and maintain team motivation

The best agile teams are built from people who work together as one unit, where each team member has both the technical and the personal skills to allow the team to become self-organized, cross-functional, and self-motivated. These are all big words that I hear in almost every agile project. Still, the criteria to make a fantastic agile team are practically impossible to achieve without one major factor: motivation towards a common goal.

Dec’22 Updates: The All-New LT Browser 2.0, XCUI App Automation with HyperExecute, And More!

Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.

How To Get Started With Cypress Debugging

One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.

How to Recognize and Hire Top QA / DevOps Engineers

With the rising demand for new services and technologies in the IT, manufacturing, healthcare, and financial sector, QA/ DevOps engineering has become the most important part of software companies. Below is a list of some characteristics to look for when interviewing a potential candidate.

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 Molotov 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