From f99b79e88b67f85d4c33e58cf7e2c440a03c24d4 Mon Sep 17 00:00:00 2001 From: Tim O'Donnell <timodonnell@gmail.com> Date: Mon, 9 Sep 2019 13:50:40 -0400 Subject: [PATCH] rename --- mhcflurry/class1_neural_network.py | 8 +------- mhcflurry/testing_utils.py | 8 +++++++- test/test_calibrate_percentile_ranks_command.py | 4 ++-- test/test_changing_allele_representations.py | 4 ++-- test/test_class1_affinity_predictor.py | 2 +- test/test_class1_neural_network.py | 4 ++-- test/test_class1_pan.py | 4 ++-- test/test_custom_loss.py | 4 ++-- test/test_download_models_class1.py | 4 ++-- test/test_multi_output.py | 4 ++-- test/test_network_merging.py | 4 ++-- test/test_predict_command.py | 4 ++-- test/test_released_predictors_on_hpv_dataset.py | 4 ++-- test/test_released_predictors_well_correlated.py | 4 ++-- test/test_speed.py | 4 ++-- test/test_train_and_related_commands.py | 4 ++-- test/test_train_pan_allele_models_command.py | 4 ++-- 17 files changed, 37 insertions(+), 37 deletions(-) diff --git a/mhcflurry/class1_neural_network.py b/mhcflurry/class1_neural_network.py index 9f22176d..277c683b 100644 --- a/mhcflurry/class1_neural_network.py +++ b/mhcflurry/class1_neural_network.py @@ -1416,10 +1416,4 @@ class Class1NeuralNetwork(object): original_model.fit = \ original_model.fit_generator = throw - session = K.get_session() - (weights_variable,) = layer.non_trainable_weights - session.run(weights_variable.initializer) - session.run(tf.assign(weights_variable, reshaped)) - # - # Previously had this but was getting sporadic not initialized errors - # layer.set_weights([reshaped]) + layer.set_weights([reshaped]) diff --git a/mhcflurry/testing_utils.py b/mhcflurry/testing_utils.py index f6cc079b..157a11af 100644 --- a/mhcflurry/testing_utils.py +++ b/mhcflurry/testing_utils.py @@ -1,7 +1,13 @@ +""" +Utilities used in MHCflurry unit tests. +""" from . import Class1NeuralNetwork -def module_cleanup(): +def cleanup(): + """ + Clear tensorflow session and other process-wide resources. + """ import keras.backend as K Class1NeuralNetwork.clear_model_cache() K.clear_session() diff --git a/test/test_calibrate_percentile_ranks_command.py b/test/test_calibrate_percentile_ranks_command.py index 4c97e80c..2dc44a0b 100644 --- a/test/test_calibrate_percentile_ranks_command.py +++ b/test/test_calibrate_percentile_ranks_command.py @@ -14,8 +14,8 @@ from mhcflurry.downloads import get_path os.environ["CUDA_VISIBLE_DEVICES"] = "" -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup def run_and_check(n_jobs=0, delete=True, additional_args=[]): diff --git a/test/test_changing_allele_representations.py b/test/test_changing_allele_representations.py index 7c70048d..38b9e12c 100644 --- a/test/test_changing_allele_representations.py +++ b/test/test_changing_allele_representations.py @@ -8,8 +8,8 @@ from mhcflurry.downloads import get_path from numpy.testing import assert_equal -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup ALLELE_TO_SEQUENCE = pandas.read_csv( get_path( diff --git a/test/test_class1_affinity_predictor.py b/test/test_class1_affinity_predictor.py index 563b6dcf..8f2b4aa0 100644 --- a/test/test_class1_affinity_predictor.py +++ b/test/test_class1_affinity_predictor.py @@ -29,7 +29,7 @@ def setup(): def teardown(): global DOWNLOADED_PREDICTOR DOWNLOADED_PREDICTOR = None - mhcflurry.testing_utils.module_cleanup() + mhcflurry.testing_utils.cleanup() # To hunt down a weird warning we were seeing in pandas. diff --git a/test/test_class1_neural_network.py b/test/test_class1_neural_network.py index e614d602..4620334a 100644 --- a/test/test_class1_neural_network.py +++ b/test/test_class1_neural_network.py @@ -13,8 +13,8 @@ from mhcflurry.class1_neural_network import Class1NeuralNetwork from mhcflurry.downloads import get_path from mhcflurry.common import random_peptides -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup def test_class1_neural_network_a0205_training_accuracy(): diff --git a/test/test_class1_pan.py b/test/test_class1_pan.py index cdb483cf..9ad87d69 100644 --- a/test/test_class1_pan.py +++ b/test/test_class1_pan.py @@ -11,8 +11,8 @@ from mhcflurry import Class1AffinityPredictor,Class1NeuralNetwork from mhcflurry.allele_encoding import AlleleEncoding from mhcflurry.downloads import get_path -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup HYPERPARAMETERS = { diff --git a/test/test_custom_loss.py b/test/test_custom_loss.py index 4c177666..2426f48d 100644 --- a/test/test_custom_loss.py +++ b/test/test_custom_loss.py @@ -11,8 +11,8 @@ import keras.backend as K from mhcflurry.custom_loss import CUSTOM_LOSSES -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup def evaluate_loss(loss, y_true, y_pred): diff --git a/test/test_download_models_class1.py b/test/test_download_models_class1.py index 5e433272..ffbf8b3c 100644 --- a/test/test_download_models_class1.py +++ b/test/test_download_models_class1.py @@ -5,7 +5,7 @@ from numpy.testing import assert_equal from mhcflurry import Class1AffinityPredictor, Class1NeuralNetwork -from mhcflurry.testing_utils import module_cleanup +from mhcflurry.testing_utils import cleanup DOWNLOADED_PREDICTOR = None @@ -19,7 +19,7 @@ def setup(): def teardown(): global DOWNLOADED_PREDICTOR DOWNLOADED_PREDICTOR = None - module_cleanup() + cleanup() def predict_and_check( diff --git a/test/test_multi_output.py b/test/test_multi_output.py index efbcccf0..b4254b56 100644 --- a/test/test_multi_output.py +++ b/test/test_multi_output.py @@ -12,8 +12,8 @@ logging.getLogger('tensorflow').disabled = True from mhcflurry.class1_neural_network import Class1NeuralNetwork from mhcflurry.common import random_peptides -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup def test_multi_output(): diff --git a/test/test_network_merging.py b/test/test_network_merging.py index 8d1aca24..56683a52 100644 --- a/test/test_network_merging.py +++ b/test/test_network_merging.py @@ -5,7 +5,7 @@ from mhcflurry import Class1AffinityPredictor, Class1NeuralNetwork from mhcflurry.common import random_peptides from mhcflurry.downloads import get_path -from mhcflurry.testing_utils import module_cleanup +from mhcflurry.testing_utils import cleanup logging.getLogger('tensorflow').disabled = True @@ -23,7 +23,7 @@ def setup(): def teardown(): global PAN_ALLELE_PREDICTOR PAN_ALLELE_PREDICTOR = None - module_cleanup() + cleanup() def test_merge(): diff --git a/test/test_predict_command.py b/test/test_predict_command.py index 7d4d9340..507d7c4a 100644 --- a/test/test_predict_command.py +++ b/test/test_predict_command.py @@ -6,8 +6,8 @@ from numpy.testing import assert_equal from mhcflurry import predict_command -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup TEST_CSV = ''' Allele,Peptide,Experiment diff --git a/test/test_released_predictors_on_hpv_dataset.py b/test/test_released_predictors_on_hpv_dataset.py index 02928f6d..33692574 100644 --- a/test/test_released_predictors_on_hpv_dataset.py +++ b/test/test_released_predictors_on_hpv_dataset.py @@ -13,7 +13,7 @@ from nose.tools import eq_, assert_less, assert_greater, assert_almost_equal from mhcflurry import Class1AffinityPredictor from mhcflurry.downloads import get_path -from mhcflurry.testing_utils import module_cleanup +from mhcflurry.testing_utils import cleanup def data_path(name): @@ -41,7 +41,7 @@ def setup(): def teardown(): global PREDICTORS PREDICTORS = None - module_cleanup() + cleanup() def test_on_hpv(df=DF): diff --git a/test/test_released_predictors_well_correlated.py b/test/test_released_predictors_well_correlated.py index 67d0e98e..82071d65 100644 --- a/test/test_released_predictors_well_correlated.py +++ b/test/test_released_predictors_well_correlated.py @@ -15,7 +15,7 @@ from mhcflurry.encodable_sequences import EncodableSequences from mhcflurry.downloads import get_path from mhcflurry.common import random_peptides -from mhcflurry.testing_utils import module_cleanup +from mhcflurry.testing_utils import cleanup PREDICTORS = None @@ -33,7 +33,7 @@ def setup(): def teardown(): global PREDICTORS PREDICTORS = None - module_cleanup() + cleanup() def test_correlation( diff --git a/test/test_speed.py b/test/test_speed.py index 4f0d473e..eb604a50 100644 --- a/test/test_speed.py +++ b/test/test_speed.py @@ -18,7 +18,7 @@ from mhcflurry.encodable_sequences import EncodableSequences from mhcflurry.common import random_peptides from mhcflurry.downloads import get_path -from mhcflurry.testing_utils import module_cleanup +from mhcflurry.testing_utils import cleanup ALLELE_SPECIFIC_PREDICTOR = Class1AffinityPredictor.load( get_path("models_class1", "models")) @@ -43,7 +43,7 @@ def setup(): def teardown(): global PREDICTORS PREDICTORS = None - module_cleanup() + cleanup() DEFAULT_NUM_PREDICTIONS = 10000 diff --git a/test/test_train_and_related_commands.py b/test/test_train_and_related_commands.py index 09ae60e5..7b893f7b 100644 --- a/test/test_train_and_related_commands.py +++ b/test/test_train_and_related_commands.py @@ -14,8 +14,8 @@ from numpy.testing import assert_array_less, assert_equal from mhcflurry import Class1AffinityPredictor from mhcflurry.downloads import get_path -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup os.environ["CUDA_VISIBLE_DEVICES"] = "" diff --git a/test/test_train_pan_allele_models_command.py b/test/test_train_pan_allele_models_command.py index dd69e810..51c7c3ff 100644 --- a/test/test_train_pan_allele_models_command.py +++ b/test/test_train_pan_allele_models_command.py @@ -15,8 +15,8 @@ from numpy.testing import assert_equal, assert_array_less from mhcflurry import Class1AffinityPredictor,Class1NeuralNetwork from mhcflurry.downloads import get_path -from mhcflurry.testing_utils import module_cleanup -teardown = module_cleanup +from mhcflurry.testing_utils import cleanup +teardown = cleanup os.environ["CUDA_VISIBLE_DEVICES"] = "" -- GitLab