def test_import_entrez(self): TEST_RECORD_ID = "6273291" TEST_RECORD_LABEL = "testRecord" if internet_on(): import_reference_genome_from_ncbi( self.test_project, TEST_RECORD_LABEL, TEST_RECORD_ID, 'genbank')
def update_net_status(): global net_status if utils.internet_on(): net_status = "ON" else: net_status = "OFF" return True
def test_run_pipeline__genbank_from_ncbi_with_spaces_in_label(self): """Tests the pipeline where the genome is imported from NCBI with spaces in the name. """ if not internet_on(): return MG1655_ACCESSION = 'NC_000913.3' MG1655_LABEL = 'mg1655 look a space' ref_genome = import_reference_genome_from_ncbi(self.project, MG1655_LABEL, MG1655_ACCESSION, 'genbank') sample_list = [self.experiment_sample] alignment_group_obj, async_result = run_pipeline( 'name_placeholder', ref_genome, sample_list) # Block until pipeline finishes. while not async_result.ready(): time.sleep(1) if async_result.status == 'FAILURE': self.fail('Async task failed.') alignment_group_obj = AlignmentGroup.objects.get( id=alignment_group_obj.id) self.assertEqual( 1, len(alignment_group_obj.experimentsampletoalignment_set.all())) self.assertEqual(AlignmentGroup.STATUS.COMPLETED, alignment_group_obj.status)
def wait_internet_conn(): if internet_on(): GPIOSetup.ready() return time.sleep(1) GPIOSetup.no_internet() wait_internet_conn()
class TestIntegration(TestCase): @unittest.skipIf( not utils.internet_on(), "Cannot reach internet to download reference model." ) def test_segmentation_pretrained_test_only(self): t1 = torch.randn(3, 2, 2, requires_grad=True) t2 = torch.randn(3, 2, 2, requires_grad=True) tr1 = torch.randn(2, 2, requires_grad=True) tr2 = torch.randn(2, 2, requires_grad=True) model_name = "fcn_resnet101" num_classes = 21 aux_loss = "store_true" model = torchvision.models.segmentation.__dict__[model_name]( num_classes=num_classes, aux_loss=aux_loss, pretrained=True ) model.eval() # tensor run t_input = torch.stack([t1, t2]) t_target = torch.stack([tr1, tr2]) confmat = ConfusionMatrix(num_classes) output1 = model(t_input) output1 = output1["out"] confmat.update(t_target.flatten(), output1.argmax(1).flatten()) confmat.reduce_from_all_processes() # nt run nt_t1 = t1.clone().detach() nt_t2 = t2.clone().detach() nt_tr1 = tr1.clone().detach() nt_tr2 = tr2.clone().detach() nt_input = nestedtensor.nested_tensor([nt_t1, nt_t2], requires_grad=True) nt_target = nestedtensor.nested_tensor([nt_tr1, nt_tr2], requires_grad=True) confmat2 = ConfusionMatrix(num_classes) output2 = model(nt_input) output2 = output2["out"] for a, b in zip(nt_target, output2): confmat2.update(a.flatten(), b.argmax(0).flatten()) confmat2.reduce_from_all_processes() self.assertEqual(confmat.mat, confmat2.mat) # grad test output1_sum = output1[0].sum() output2_sum = output2[0].sum() self.assertEqual(output1_sum, output2_sum) output1_sum.backward() output2_sum.backward() self.assertEqual(t1.grad, nt_input[0].grad) self.assertEqual(t2.grad, nt_input[1].grad)
def main(): while True: initcode = input("Selector Barcode: ") if utils.internet_on(): pass if initcode == "QUIT": utils.quit_log() exit() elif bool(initcode == "") | bool(initcode == " "): print("Blank input. Try again.") main() elif initcode == "SHOP": itemcode = get_barcode(initcode) history.check_in(itemcode) current.update_location(itemcode, initcode) print(itemcode + " checked into SHOP.") elif initcode == "RETIRE": itemcode = get_barcode(initcode) history.check_out(itemcode, initcode) current.update_location(itemcode, initcode) print(itemcode + " retired. Thank you for your service, " + itemcode + ".") elif initcode == "CHKLOC": itemcode = get_barcode(initcode) print(itemcode + " is checked out to " + current.where_is(itemcode) + ".") else: itemcode = get_barcode(initcode) if current.where_is(itemcode) == initcode: print(itemcode + " is already checked out to " + initcode + ". Please scan another.") main() else: history.check_out(itemcode, initcode) current.update_location(itemcode, initcode) print(itemcode + " checked out to " + initcode + ".")
class TestIntegration(TestCase): @unittest.skipIf( not utils.internet_on(), "Cannot reach internet to download reference model." ) def test_segmentation_pretrained_test_only(self): def _test(seed, model_factory, use_confmat, num_classes=21): torch.manual_seed(seed) t1 = torch.randn(3, 3, 4, requires_grad=True) t2 = torch.randn(3, 3, 4, requires_grad=True) tr1 = torch.randn(3, 4, requires_grad=True) tr2 = torch.randn(3, 4, requires_grad=True) model1 = model_factory() # model1 = torchvision.models.segmentation.__dict__[model_name]( # num_classes=num_classes, aux_loss=aux_loss, pretrained=True # ) # model1.eval() # tensor run t_input = torch.stack([t1, t2]) t_target = torch.stack([tr1, tr2]) if use_confmat: confmat = ConfusionMatrix(num_classes) output1 = model1(t_input) if use_confmat: output1 = output1["out"] else: output1 = output1["0"] if use_confmat: confmat.update(t_target.flatten(), output1.argmax(1).flatten()) confmat.reduce_from_all_processes() # nt run # model2 = torchvision.models.segmentation.__dict__[model_name]( # num_classes=num_classes, aux_loss=aux_loss, pretrained=True # ) # model2.eval() model2 = model_factory() nt_t1 = t1.clone().detach() nt_t2 = t2.clone().detach() nt_tr1 = tr1.clone().detach() nt_tr2 = tr2.clone().detach() nt_input = nestedtensor.nested_tensor( [nt_t1, nt_t2], requires_grad=True) nt_target = nestedtensor.nested_tensor( [nt_tr1, nt_tr2], requires_grad=True) if use_confmat: confmat2 = ConfusionMatrix(num_classes) output2 = model2(nt_input) if use_confmat: output2 = output2["out"] else: output2 = output2["0"] if use_confmat: for a, b in zip(nt_target, output2): confmat2.update(a.flatten(), b.argmax(0).flatten()) if use_confmat: confmat2.reduce_from_all_processes() self.assertEqual(confmat.mat, confmat2.mat) # grad test output1_sum = output1.sum() output2_sum = output2.sum() self.assertEqual(output1_sum, output2_sum) output1_sum.backward() output2_sum.backward() for (n1, p1), (n2, p2) in zip(model1.named_parameters(), model2.named_parameters()): if p1.grad is not None: self.assertEqual(p1.grad, p2.grad) else: self.assertIsNone(p2.grad) # TODO: Re-enable under autograd support self.assertEqual(t1.grad, nt_input.grad[0]) self.assertEqual(t2.grad, nt_input.grad[1]) _test(1010, lambda: torchvision.models.segmentation.__dict__["fcn_resnet101"]( num_classes=21, aux_loss="store_true", pretrained=True ).eval(), True)