How to use create_model method in localstack

Best Python code snippet using localstack_python

0002_data.py

Source:0002_data.py Github

copy

Full Screen

1from django.db import migrations2from core.models import Hour, Minute, Timing3def create_model(model):4 model.save()5 return model6def init_data(apps, schema_editor):7 # Hour8 hour_0 = create_model(Hour(title="00", hour=0))9 hour_1 = create_model(Hour(title="01", hour=1))10 hour_2 = create_model(Hour(title="02", hour=1))11 hour_3 = create_model(Hour(title="03", hour=1))12 hour_4 = create_model(Hour(title="04", hour=1))13 hour_5 = create_model(Hour(title="05", hour=1))14 hour_6 = create_model(Hour(title="06", hour=1))15 hour_7 = create_model(Hour(title="07", hour=1))16 hour_8 = create_model(Hour(title="08", hour=1))17 hour_9 = create_model(Hour(title="09", hour=1))18 hour_10 = create_model(Hour(title="10", hour=1))19 hour_11 = create_model(Hour(title="11", hour=1))20 hour_12 = create_model(Hour(title="12", hour=1))21 hour_13 = create_model(Hour(title="13", hour=1))22 hour_14 = create_model(Hour(title="14", hour=1))23 hour_15 = create_model(Hour(title="15", hour=1))24 hour_16 = create_model(Hour(title="16", hour=1))25 hour_17 = create_model(Hour(title="17", hour=1))26 hour_18 = create_model(Hour(title="18", hour=1))27 hour_19 = create_model(Hour(title="19", hour=1))28 hour_20 = create_model(Hour(title="20", hour=1))29 hour_21 = create_model(Hour(title="21", hour=1))30 hour_22 = create_model(Hour(title="22", hour=1))31 hour_23 = create_model(Hour(title="23", hour=1))32 # Minute33 minute_0 = create_model(Minute(title="00", minute=0))34 minute_1 = create_model(Minute(title="01", minute=1))35 minute_2 = create_model(Minute(title="02", minute=2))36 minute_3 = create_model(Minute(title="03", minute=3))37 minute_4 = create_model(Minute(title="04", minute=4))38 minute_5 = create_model(Minute(title="05", minute=5))39 minute_6 = create_model(Minute(title="06", minute=6))40 minute_7 = create_model(Minute(title="07", minute=7))41 minute_8 = create_model(Minute(title="08", minute=8))42 minute_9 = create_model(Minute(title="09", minute=9))43 minute_10 = create_model(Minute(title="10", minute=10))44 minute_11 = create_model(Minute(title="11", minute=11))45 minute_12 = create_model(Minute(title="12", minute=12))46 minute_13 = create_model(Minute(title="13", minute=13))47 minute_14 = create_model(Minute(title="14", minute=14))48 minute_15 = create_model(Minute(title="15", minute=15))49 minute_16 = create_model(Minute(title="16", minute=16))50 minute_17 = create_model(Minute(title="17", minute=17))51 minute_18 = create_model(Minute(title="18", minute=18))52 minute_19 = create_model(Minute(title="19", minute=19))53 minute_20 = create_model(Minute(title="20", minute=20))54 minute_21 = create_model(Minute(title="21", minute=21))55 minute_22 = create_model(Minute(title="22", minute=22))56 minute_23 = create_model(Minute(title="23", minute=23))57 minute_24 = create_model(Minute(title="24", minute=24))58 minute_25 = create_model(Minute(title="25", minute=25))59 minute_26 = create_model(Minute(title="26", minute=26))60 minute_27 = create_model(Minute(title="27", minute=27))61 minute_28 = create_model(Minute(title="28", minute=28))62 minute_29 = create_model(Minute(title="29", minute=29))63 minute_30 = create_model(Minute(title="30", minute=30))64 minute_31 = create_model(Minute(title="31", minute=31))65 minute_32 = create_model(Minute(title="32", minute=32))66 minute_33 = create_model(Minute(title="33", minute=33))67 minute_34 = create_model(Minute(title="34", minute=34))68 minute_35 = create_model(Minute(title="35", minute=35))69 minute_36 = create_model(Minute(title="36", minute=36))70 minute_37 = create_model(Minute(title="37", minute=37))71 minute_38 = create_model(Minute(title="38", minute=38))72 minute_39 = create_model(Minute(title="39", minute=39))73 minute_40 = create_model(Minute(title="40", minute=40))74 minute_41 = create_model(Minute(title="41", minute=41))75 minute_42 = create_model(Minute(title="42", minute=42))76 minute_43 = create_model(Minute(title="43", minute=43))77 minute_44 = create_model(Minute(title="44", minute=44))78 minute_45 = create_model(Minute(title="45", minute=45))79 minute_46 = create_model(Minute(title="46", minute=46))80 minute_47 = create_model(Minute(title="47", minute=47))81 minute_48 = create_model(Minute(title="48", minute=48))82 minute_49 = create_model(Minute(title="49", minute=49))83 minute_50 = create_model(Minute(title="50", minute=50))84 minute_51 = create_model(Minute(title="51", minute=51))85 minute_52 = create_model(Minute(title="52", minute=52))86 minute_53 = create_model(Minute(title="53", minute=53))87 minute_54 = create_model(Minute(title="54", minute=54))88 minute_55 = create_model(Minute(title="55", minute=55))89 minute_56 = create_model(Minute(title="56", minute=56))90 minute_57 = create_model(Minute(title="57", minute=57))91 minute_58 = create_model(Minute(title="58", minute=58))92 minute_59 = create_model(Minute(title="59", minute=59))93 # Timing94 timing_5 = create_model(Timing(title='5 минут', minutes=5))95 timing_10 = create_model(Timing(title='10 минут', minutes=10))96 timing_15 = create_model(Timing(title='15 минут', minutes=15))97 timing_30 = create_model(Timing(title='30 минут', minutes=30))98 timing_45 = create_model(Timing(title='45 минут', minutes=45))99 timing_60 = create_model(Timing(title='1 час', minutes=60))100 timing_120 = create_model(Timing(title='2 часа', minutes=120))101 timing_180 = create_model(Timing(title='3 часа', minutes=180))102 timing_360 = create_model(Timing(title='6 часов', minutes=360))103 timing_720 = create_model(Timing(title='12 часов', minutes=720))104 timing_1440 = create_model(Timing(title='1 день', minutes=1440))105class Migration(migrations.Migration):106 dependencies = [107 ('core', '0002_minute')108 ]109 operations = [110 migrations.RunPython(init_data),...

Full Screen

Full Screen

checkpoint.py

Source:checkpoint.py Github

copy

Full Screen

...7from mamba_core.utils.model_serialization import load_state_dict8from tempfile import TemporaryDirectory9from torch import nn10class TestCheckpointer(unittest.TestCase):11 def create_model(self):12 return nn.Sequential(nn.Linear(2, 3), nn.Linear(3, 1))13 def create_complex_model(self):14 m = nn.Module()15 m.block1 = nn.Module()16 m.block1.layer1 = nn.Linear(2, 3)17 m.layer2 = nn.Linear(3, 2)18 m.res = nn.Module()19 m.res.layer2 = nn.Linear(3, 2)20 state_dict = OrderedDict()21 state_dict["layer1.weight"] = torch.rand(3, 2)22 state_dict["layer1.bias"] = torch.rand(3)23 state_dict["layer2.weight"] = torch.rand(2, 3)24 state_dict["layer2.bias"] = torch.rand(2)25 state_dict["res.layer2.weight"] = torch.rand(2, 3)26 state_dict["res.layer2.bias"] = torch.rand(2)27 return m, state_dict28 def test_from_last_checkpoint_model(self):29 # test that loading works even if they differ by a prefix30 for trained_model, fresh_model in [31 (self.create_model(), self.create_model()),32 (nn.DataParallel(self.create_model()), self.create_model()),33 (self.create_model(), nn.DataParallel(self.create_model())),34 (35 nn.DataParallel(self.create_model()),36 nn.DataParallel(self.create_model()),37 ),38 ]:39 with TemporaryDirectory() as f:40 checkpointer = Checkpointer(41 trained_model, save_dir=f, save_to_disk=True42 )43 checkpointer.save("checkpoint_file")44 # in the same folder45 fresh_checkpointer = Checkpointer(fresh_model, save_dir=f)46 self.assertTrue(fresh_checkpointer.has_checkpoint())47 self.assertEqual(48 fresh_checkpointer.get_checkpoint_file(),49 os.path.join(f, "checkpoint_file.pth"),50 )51 _ = fresh_checkpointer.load()52 for trained_p, loaded_p in zip(53 trained_model.parameters(), fresh_model.parameters()54 ):55 # different tensor references56 self.assertFalse(id(trained_p) == id(loaded_p))57 # same content58 self.assertTrue(trained_p.equal(loaded_p))59 def test_from_name_file_model(self):60 # test that loading works even if they differ by a prefix61 for trained_model, fresh_model in [62 (self.create_model(), self.create_model()),63 (nn.DataParallel(self.create_model()), self.create_model()),64 (self.create_model(), nn.DataParallel(self.create_model())),65 (66 nn.DataParallel(self.create_model()),67 nn.DataParallel(self.create_model()),68 ),69 ]:70 with TemporaryDirectory() as f:71 checkpointer = Checkpointer(72 trained_model, save_dir=f, save_to_disk=True73 )74 checkpointer.save("checkpoint_file")75 # on different folders76 with TemporaryDirectory() as g:77 fresh_checkpointer = Checkpointer(fresh_model, save_dir=g)78 self.assertFalse(fresh_checkpointer.has_checkpoint())79 self.assertEqual(fresh_checkpointer.get_checkpoint_file(), "")80 _ = fresh_checkpointer.load(os.path.join(f, "checkpoint_file.pth"))81 for trained_p, loaded_p in zip(...

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