Best Python code snippet using localstack_python
template_deployer.py
Source:template_deployer.py
...1180 ssm_client = aws_stack.connect_to_service("ssm")1181 param = ssm_client.get_parameter(Name=default_value)1182 return param["Parameter"]["Value"]1183 return None1184 def apply_parameter_changes(self, old_stack, new_stack) -> None:1185 parameters = {1186 p["ParameterKey"]: p1187 for p in old_stack.metadata["Parameters"] # go through current parameter values1188 }1189 for logical_id, value in new_stack.template["Parameters"].items():1190 default = value.get("Default")1191 provided_param_value = parameters.get(logical_id)1192 param = {1193 "ParameterKey": logical_id,1194 "ParameterValue": provided_param_value if default is None else default,1195 }1196 if default is not None:1197 resolved_value = self.resolve_param(logical_id, value.get("Type"), default)1198 if resolved_value is not None:1199 param["ResolvedValue"] = resolved_value1200 parameters[logical_id] = param1201 parameters.update({p["ParameterKey"]: p for p in new_stack.metadata["Parameters"]})1202 for change_set in new_stack.change_sets:1203 parameters.update({p["ParameterKey"]: p for p in change_set.metadata["Parameters"]})1204 # TODO: unclear/undocumented behavior in implicitly updating old_stack parameter here1205 old_stack.metadata["Parameters"] = [v for v in parameters.values() if v]1206 # TODO: fix circular import with cloudformation_api.py when importing Stack here1207 def construct_changes(1208 self,1209 existing_stack,1210 new_stack,1211 initialize=False,1212 change_set_id=None,1213 append_to_changeset=False,1214 ):1215 from localstack.services.cloudformation.cloudformation_api import StackChangeSet1216 old_resources = existing_stack.template["Resources"]1217 new_resources = new_stack.template["Resources"]1218 deletes = [val for key, val in old_resources.items() if key not in new_resources]1219 adds = [val for key, val in new_resources.items() if initialize or key not in old_resources]1220 modifies = [val for key, val in new_resources.items() if key in old_resources]1221 changes = []1222 for action, items in (("Remove", deletes), ("Add", adds), ("Modify", modifies)):1223 for item in items:1224 item["Properties"] = item.get("Properties", {})1225 change = self.get_change_config(action, item, change_set_id=change_set_id)1226 changes.append(change)1227 # append changes to change set1228 if append_to_changeset and isinstance(new_stack, StackChangeSet):1229 new_stack.changes.extend(changes)1230 return changes1231 def apply_changes(1232 self,1233 existing_stack,1234 new_stack,1235 stack_name,1236 change_set_id=None,1237 initialize=False,1238 action=None,1239 ):1240 old_resources = existing_stack.template["Resources"]1241 new_resources = new_stack.template["Resources"]1242 action = action or "CREATE"1243 self.init_resource_status(old_resources, action="UPDATE")1244 # apply parameter changes to existing stack1245 self.apply_parameter_changes(existing_stack, new_stack)1246 # construct changes1247 changes = self.construct_changes(1248 existing_stack,1249 new_stack,1250 initialize=initialize,1251 change_set_id=change_set_id,1252 )1253 # check if we have actual changes in the stack, and prepare properties1254 contains_changes = False1255 for change in changes:1256 res_action = change["ResourceChange"]["Action"]1257 resource = new_resources.get(change["ResourceChange"]["LogicalResourceId"])1258 if res_action != "Modify" or self.resource_config_differs(resource):1259 contains_changes = True...
trainer.py
Source:trainer.py
...98 modified_arg += char99 tensorboard_comment += modified_arg100 #params["tb_comment"] = tensorboard_comment101 return tensorboard_comment102def apply_parameter_changes(parameters, env, verbose):103 # NN architectures:104 hidden_size = parameters["hidden_size"]105 # Save in the sense of enough non-linearities per block:106 save_feature_block = [{"name": "linear", "neurons": hidden_size, "act_func": "relu"},107 {"name": "linear", "neurons": hidden_size}]108 save_hidden_block = [{"name": "linear", "neurons": hidden_size, "act_func": "relu"},109 {"name": "linear", "neurons": hidden_size, "act_func": "relu"}]110 111 thin_block = [{"name": "linear", "neurons": hidden_size, "act_func": "relu"}]112 test_block = [{"name": "linear", "neurons": 64, "act_func": "relu"}]113 standard_hidden_block = thin_block114 standard_feature_block = thin_block115 layers_feature_vector = standard_hidden_block116 layers_feature_merge = standard_feature_block117 layers_action = standard_feature_block118 layers_state_action_merge = standard_feature_block119 layers_r = standard_hidden_block120 layers_Q = standard_hidden_block121 layers_V = standard_hidden_block122 layers_actor = standard_hidden_block123 mnhi_early = [{"name": "conv", "filters": 32, "kernel_size": 8, "stride": 4, "act_func": "relu"},124 {"name": "conv", "filters": 64, "kernel_size": 4, "stride": 2, "act_func": "relu"},125 {"name": "conv", "filters": 64, "kernel_size": 2, "stride": 1, "act_func": "relu"}126 ]127 mnhi_later = [{"name": "conv", "filters": 32, "kernel_size": 8, "stride": 4, "act_func": "relu"},128 {"name": "conv", "filters": 64, "kernel_size": 4, "stride": 2, "act_func": "relu"},129 {"name": "conv", "filters": 64, "kernel_size": 3, "stride": 1, "act_func": "relu"}130 ]131 vizdoom_winner = [{"name": "conv", "filters": 16, "kernel_size": 3, "stride": 2, "act_func": "relu"},132 {"name": "conv", "filters": 32, "kernel_size": 3, "stride": 2, "act_func": "relu"},133 {"name": "conv", "filters": 64, "kernel_size": 3, "stride": 2, "act_func": "relu"},134 {"name": "conv", "filters": 128, "kernel_size": 3, "stride": 1, "act_func": "relu"},135 {"name": "conv", "filters": 256, "kernel_size": 3, "stride": 1, "act_func": "relu"}136 ]137 own_arch = [{"name": "conv", "filters": 16, "kernel_size": 3, "stride": 2, "act_func": "relu"},138 {"name": "conv", "filters": 32, "kernel_size": 3, "stride": 2, "act_func": "relu"},139 {"name": "conv", "filters": 64, "kernel_size": 3, "stride": 2, "act_func": "relu"},140 {"name": "conv", "filters": 128, "kernel_size": 3, "stride": 2, "act_func": "relu"},141 {"name": "conv", "filters": 256, "kernel_size": 3, "stride": 1, "act_func": "relu"}142 ]143 # TODO: define R2D2 conv architecture! (IMPALA uses the same)144 layers_conv = standard_hidden_block145 parameters.update({146 # NN architecture setup:147 "layers_feature_vector": layers_feature_vector, "layers_state_action_merge": layers_state_action_merge,148 "layers_action": layers_action,149 "layers_feature_merge": layers_feature_merge, "layers_r": layers_r, "layers_Q": layers_Q,150 "layers_V": layers_V,151 "layers_actor": layers_actor152 })153 154 #Convert strings in hyperparams to objects:155 # optimizer:156 if parameters["optimizer"] == "RAdam":157 parameters["optimizer"] = RAdam158 elif parameters["optimizer"] == "Adam":159 parameters["optimizer"] = torch.optim.Adam160 # Conv layers:161 if parameters["layers_conv"] == "mnhi_early":162 parameters["layers_conv"] = mnhi_early163 elif parameters["layers_conv"] == "mnhi_later":164 parameters["layers_conv"] = mnhi_later165 elif parameters["layers_conv"] == "vizdoom_winner":166 parameters["layers_conv"] = vizdoom_winner167 elif parameters["layers_conv"] == "own":168 parameters["layers_conv"] = own_arch169 atari_envs = ['adventure', 'airraid', 'alien', 'amidar', 'assault', 'asterix', 'asteroids', 'atlantis',170 'bank_heist', 'battlezone', 'beam_rider', 'berzerk', 'bowling', 'boxing', 'breakout', 'carnival',171 'centipede', 'choppercommand', 'crazyclimber', 'defender', 'demonattack', 'doubledunk',172 'elevatoraction', 'enduro', 'fishingderby', 'freeway', 'frostbite', 'gopher', 'gravitar',173 'hero', 'icehockey', 'jamesbond', 'journey_escape', 'kangaroo', 'krull', 'kungfumaster',174 'montezuma_revenge', 'ms_pacman', 'namethisgame', 'phoenix', 'pitfall', 'pong', 'pooyan',175 'private_eye', 'qbert', 'riverraid', 'road_runner', 'robotank', 'seaquest', 'skiing',176 'solaris', 'spaceinvaders', 'stargunner', 'tennis', 'timepilot', 'tutankham', 'upndown',177 'venture', 'videopinball', 'wizardofwor', 'yars_revenge', 'zaxxon']178 if "MineRL" in env:179 if verbose:180 print("MineRL env!")181 use_hierarchical_action_wrapper = True182 parameters["convert_2_torch_wrapper"] = Convert2TorchWrapper183 if use_hierarchical_action_wrapper:184 parameters["action_wrapper"] = HierarchicalActionWrapper185 else:186 parameters["action_wrapper"] = SerialDiscreteActionWrapper187 parameters["use_MineRL_policy"] = True188 #if "Pickaxe" in env or "Diamond" in env:189 # params["use_MineRL_policy"] = True190 elif any([atari_env in env.lower() for atari_env in atari_envs]):191 parameters["convert_2_torch_wrapper"] = AtariObsWrapper192 if verbose:193 print("Atari env!")194 else:195 parameters["convert_2_torch_wrapper"] = DefaultWrapper196 return parameters197class Trainer:198 def __init__(self, env_name, **kwargs):199 # Set up hyperparameters:200 hyperparameters = get_default_hyperparameters()201 hyperparameters.update(kwargs)202 verbose = hyperparameters["verbose"]203 hyperparameters = apply_parameter_changes(hyperparameters, env_name, verbose)204 self.hyperparameters = hyperparameters205 206 # Create tensorboard experiment comment:207 self.tb_comment = create_comment(hyperparameters["tb_comment"], env_name, kwargs)208 if verbose:209 print("Tensorboard comment: ", self.tb_comment)210 211 # Init logging:212 self.path = os.getcwd()213 self.do_log = hyperparameters["log"]214 self.log = Log(self.path + '/tb_log', self.do_log, self.tb_comment)215 self.verbose = verbose216 217 # Set device...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!