How to use _distill method in Slash

Best Python code snippet using slash

polyshapes.py

Source:polyshapes.py Github

copy

Full Screen

...47 return self.__class__(newverts)48 49 __add__ = __radd__ = translate50 51 def _distill(self):52 53 edges = []54 unique = set()55 56 for f in self.faces:57 for pair in zip(f , f[1:] + (f[0],)):58 unique.add( tuple(sorted(pair)) )59 60 for edge in unique:61 edges.append( Edge(self.vertices[edge[0]],self.vertices[edge[1]]) )62 63 return edges 64 65 def draw(self):66 # VPython wireframe view, native to stickworks.py67 for e in self.edges:68 e.draw()69 70 71class Amodule (Polyhedron) :72 pass73 74class Bmodule (Polyhedron) :75 pass76 77class Mite (Polyhedron) :78 79 def __init__(self,80 verts = dict(j = Vector(( 0, 1, 0)),81 o = Vector(( 0, 0, 0)),82 r = Vector(( 1, 0, 1)),83 s = Vector(( 1, 0,-1)))):84 85 # 4 vertices86 self.vertices = verts87 88 # 4 faces89 self.faces = (('j','o','r'),('j','r','s'),('j','s','o'),('o','r','s'))90 91 self.edges = self._distill()92 93class Smite (Polyhedron) :94 pass95 96class Coupler (Polyhedron) :97 98 def __init__(self,99 verts = dict(j = Vector(( 0, 1, 0)),100 l = Vector(( 0, -1, 0)),101 q = Vector((-1, 0, 1)),102 r = Vector(( 1, 0, 1)),103 s = Vector(( 1, 0,-1)),104 t = Vector((-1, 0,-1)))):105 106 # 6 vertices107 self.vertices = verts108 109 # 8 faces110 self.faces = (('j','q','r'),('j','r','s'),('j','s','t'),('j','t','q'),111 ('l','q','r'),('l','r','s'),('l','s','t'),('l','t','q'))112 113 self.edges = self._distill()114 115class Tetrahedron (Polyhedron) :116 117 def __init__(self,118 verts = dict(a = Vector((-1, -1, 1)),119 b = Vector((-1, 1, -1)),120 c = Vector((1, 1, 1)),121 d = Vector((1, -1, -1)))):122 """123 Imagine a cube centered at the origin and with124 a positive octant vertex at (1,1,1). Inscribe125 a regular tetrahedron as six face diagonals therein.126 """127 # 4 vertices128 self.vertices = verts129 130 # 4 faces131 self.faces = (('a','b','c'),('a','c','d'),132 ('a','d','b'),('b','d','c'))133 134 self.edges = self._distill()135 136class Cube (Polyhedron):137 138 def __init__(self, verts = dict( a = Vector((-1, -1, 1)),139 b = Vector((-1, 1, -1)),140 c = Vector((1, 1, 1)),141 d = Vector((1, -1, -1)),142 e = Vector((1, 1, -1)),143 f = Vector((1, -1, 1)),144 g = Vector((-1, -1, -1)),145 h = Vector((-1, 1, 1)))):146 147 # 8 vertices148 self.vertices = verts149 150 # 6 faces151 self.faces = (('a','f','c','h'),('h','c','e','b'),152 ('b','e','d','g'),('g','d','f','a'),153 ('c','f','d','e'),('a','h','b','g'))154 155 self.edges = self._distill()156 157class Octahedron (Polyhedron):158 159 def __init__(self, verts = dict( i = Vector(( 0, 0, 1)),160 j = Vector(( 0, 1, 0)),161 k = Vector(( 0, 0,-1)),162 l = Vector(( 0,-1, 0)),163 m = Vector(( 1, 0, 0)),164 n = Vector((-1, 0, 0)))):165 166 # 6 vertices167 self.vertices = verts168 169 # 8 faces170 self.faces = (('i','l','m'),('i','m','j'),('i','j','n'),('i','n','l'), 171 ('k','l','m'),('k','m','j'),('k','j','n'),('k','n','l'))172 173 self.edges = self._distill()174 175class Dodecahedron (Polyhedron):176 pass177 178class Icosahedron (Polyhedron):179 180 def __init__(self, verts = dict(181 # 12 vertices at the corners of 3 mutually182 # orthogonal golden rectangles183 xya=Vector(( phi/2, 0.5, 0.0)), # phi rectangle in xy184 xyb=Vector(( phi/2,-0.5, 0.0)),185 xyc=Vector((-phi/2,-0.5, 0.0)),186 xyd=Vector((-phi/2, 0.5, 0.0)),187 #-----------------------------188 xza=Vector((-0.5, 0.0, phi/2)), # Phi rectangle in xz 189 xzb=Vector(( 0.5, 0.0, phi/2)),190 xzc=Vector(( 0.5, 0.0,-phi/2)),191 xzd=Vector((-0.5, 0.0,-phi/2)),192 #-----------------------------193 yza=Vector(( 0.0, phi/2, 0.5)), # Phi rectangle in yz 194 yzb=Vector(( 0.0, phi/2,-0.5)),195 yzc=Vector(( 0.0,-phi/2,-0.5)),196 yzd=Vector(( 0.0,-phi/2, 0.5)),197 )):198 199 # 12 vertices200 self.vertices = verts201 202 # 20 equiangular triangles203 self.faces = (204 ('xza','xzb','yzd'),205 ('yzd','xzb','xyb'),206 ('xyb','xzb','xya'),207 ('xya','yza','xzb'),208 ('xzb','yza','xza'),209 210 ('xzd','xzc','yzb'),211 ('yzb','xzd','xyd'),212 ('xyd','xzd','xyc'),213 ('xyc','xzd','yzc'),214 ('yzc','xzd','xzc'),215 216 ('xyd','yzb','yza'),217 ('yza','yzb','xya'),218 ('xya','yzb','xzc'),219 ('xzc','xya','xyb'),220 ('xyb','xzc','yzc'),221 ('yzc','xyb','yzd'),222 ('yzd','yzc','xyc'),223 ('xyc','yzd','xza'),224 ('xza','xyc','xyd'),225 ('xyd','xza','yza')226 )227 228 229 self.edges = self._distill()230 231 self.rectangles = (232 ('xya','xyb','xyc','xyd'),233 ('xza','xzb','xzc','xzd'),234 ('yza','yzb','yzc','yzd')) 235 236 def goldrects(self):237 Edge.color = green238 for r in self.rectangles:239 c0,c1,c2,c3 = [self.vertices[i] for i in r]240 Edge(c0,c1).draw()241 Edge(c1,c2).draw()242 Edge(c2,c3).draw()243 Edge(c3,c0).draw()...

Full Screen

Full Screen

runner.py

Source:runner.py Github

copy

Full Screen

1# Copyright (c) Facebook, Inc. and its affiliates.2# This source code is licensed under the MIT license found in the3# LICENSE file in the root directory of this source tree.4import argparse5from copy import deepcopy6from dataclasses import dataclass7from cli import shared_args8from foundations.runner import Runner9import models.registry10from platforms.platform import get_platform11from training import train12from distill.desc import DistillDesc13import pruning.registry14from pruning.mask import Mask15from pruning.pruned_model import PrunedModel16@dataclass17class DistillRunner(Runner):18 replicate: int19 desc: DistillDesc20 verbose: bool = True21 evaluate_every_epoch: bool = True22 @staticmethod23 def description():24 return "Train a model with distillation."25 @staticmethod26 def add_args(parser: argparse.ArgumentParser) -> None:27 shared_args.JobArgs.add_args(parser)28 DistillDesc.add_args(parser, shared_args.maybe_get_default_hparams())29 @staticmethod30 def create_from_args(args: argparse.Namespace) -> 'DistillRunner':31 return DistillRunner(args.replicate, DistillDesc.create_from_args(args),32 not args.quiet, not args.evaluate_only_at_end)33 def display_output_location(self):34 print(self.desc.run_path(self.replicate))35 def run(self):36 location = self.desc.run_path(self.replicate)37 if self.verbose and get_platform().is_primary_process:38 print('='*82 + f'\nTraining a Model with Knowledge Distillation (Replicate {self.replicate})\n' + '-'*82)39 print(self.desc.display)40 print(f'Output Location: {self.desc.run_path(self.replicate)}' + '\n' + '='*82 + '\n')41 if get_platform().is_primary_process: self.desc.save(location)42 # if get_platform().is_primary_process: self._establish_initial_weights()43 # get_platform().barrier()44 # Get the student model45 # student = models.registry.get(self.desc.model_hparams, outputs=self.desc.train_outputs)46 assert 'score-' in self.desc.model_hparams.model_name47 student = self._establish_initial_weights()48 # Get the teacher model49 teacher_model_hparams = deepcopy(self.desc.model_hparams)50 teacher_model_hparams.model_name = self.desc.distill_hparams.teacher_model_name51 teacher = models.registry.load_from_file(52 self.desc.distill_hparams.teacher_ckpt,53 teacher_model_hparams, self.desc.train_outputs54 )55 teacher_mask = Mask.load(self.desc.distill_hparams.teacher_mask)56 teacher = PrunedModel(teacher, teacher_mask)57 # Run training with knowledge distillation58 if models.registry.exists(location, self.desc.train_end_step, suffix='_distill'):59 student = models.registry.load(location,60 self.desc.train_end_step,61 self.desc.model_hparams,62 self.desc.train_outputs,63 suffix='_distill')64 else:65 train.distill_train(student, teacher, location,66 self.desc.dataset_hparams,67 self.desc.training_hparams,68 self.desc.distill_hparams,69 evaluate_every_epoch=self.evaluate_every_epoch,70 suffix='_distill')71 # Use the distilled student model to do the pruning72 student.apply_score_to_weight()73 # TODO: tweak pruning hparams to match teacher's sparsity level74 pruning.registry.get(self.desc.pruning_hparams)(student).save(location, suffix='_distill')75 # Train a new student model in the standard manner with the above mask76 new_student_model_hparams = deepcopy(self.desc.model_hparams)77 new_student_model_hparams.model_name = new_student_model_hparams.model_name.replace('score-', '')78 new_student = models.registry.load(location,79 self.desc.train_start_step,80 new_student_model_hparams,81 self.desc.train_outputs,82 strict=False,83 suffix='_score')84 new_student_mask = Mask.load(location, suffix='_distill')85 new_student = PrunedModel(new_student, new_student_mask)86 # Run standard training for the new student87 train.standard_train(new_student, location,88 self.desc.dataset_hparams,89 self.desc.training_hparams,90 start_step=self.desc.train_start_step,91 verbose=self.verbose,92 evaluate_every_epoch=self.evaluate_every_epoch,93 suffix='_post_distill')94 def _establish_initial_weights(self):95 location = self.desc.run_path(self.replicate)96 if models.registry.exists(location, self.desc.start_step, suffix='_score'):97 new_model = models.registry.load(location,98 self.desc.train_start_step,99 self.desc.model_hparams,100 self.desc.train_outputs,101 suffix='_score')102 else:103 new_model = models.registry.get(self.desc.model_hparams,104 outputs=self.desc.train_outputs)105 if get_platform().is_primary_process:106 new_model.save(location, self.desc.train_start_step, suffix='_score')...

Full Screen

Full Screen

test_globals.py

Source:test_globals.py Github

copy

Full Screen

...29 assert 'x' in dir(slash.g)30@pytest.fixture31def test_globals(is_method):32 returned = {}33 def _distill():34 returned['test_methodname'] = context.test_methodname35 if is_method:36 class test_something(slash.Test):37 def test_something(self):38 _distill()39 else:40 def test_something():41 _distill()42 run_tests_assert_success(test_something)43 return returned44@pytest.fixture(params=[True, False])45def is_method(request):...

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