def test_delete_model(self): num_models = len(mr.list_models()) model = mr.get_model(self.model_name) mr.delete_model(model) model = mr.get_model(model.id) assert model is None all_models = mr.list_models() assert len(all_models) == num_models - 1
def test_delete_model(self): model_count = len(mr.list_models()) model1 = mr.get_model(self.model_name) assert isinstance(model1, RestObj) model2 = mr.get_model(model1.id) assert model1.id == model2.id mr.delete_model(model1) model3 = mr.get_model(model1.id) assert model3 is None all_models = mr.list_models() assert len(all_models) == model_count - 1
def test_publish_sklearn(self): from sasctl.tasks import publish_model from sasctl.services.model_repository import get_model model = get_model(SCIKIT_MODEL_NAME, PROJECT_NAME) p = publish_model(model, 'maslocal', max_retries=100) assert 'score' in p.stepIds
def run_build(args): # Read configuration logging.info('Read config file.') with open(CONFIGPATH, "r") as cf: config = yaml.load(cf, Loader=yaml.FullLoader) logging.info('Set running variables') projname = args.project_name modelcontent = [ args.requirements, args.train_script, args.configfile, args.score_script ] hostname = config['workflow']['build']['hostname'] username = config['workflow']['build']['username'] password = config['workflow']['build']['password'] modelpath = config['workflow']['build']['modelpath'] logging.info('Start Viya Session') with Session(hostname=hostname, username=username, password=password, verify_ssl=False): logging.info('Get the Project object') project = mr.get_project(projname) logging.info('Check for the Champion Model') try: 'championModelName' in project.keys() except KeyError as errorkey: print(errorkey) else: logging.info('Get the champion id') championModelName = project['championModelName'] champion_id = mr.get_model(championModelName)['id'] logging.info('Get the content list') content_list = get( f"/modelRepository/models/{champion_id}/contents") logging.info('Check for file') for file in modelcontent: try: file in content_list except IndexError as errorindex: print(errorindex) else: # Write down target file for item in content_list: if item['name'] == file: logging.info(f'Get {file}') filestr = get( f"/modelRepository/models/{champion_id}/contents/{item['id']}/content" ) outfile = open(os.path.join(modelpath, file), 'w') outfile.write(filestr) logging.info(f'{file} stored.') outfile.close()
def test_publish_sklearn(self): from sasctl.tasks import publish_model from sasctl.services import model_repository as mr model = mr.get_model(SCIKIT_MODEL_NAME, PROJECT_NAME) p = publish_model(model, 'maslocal', max_retries=100) # Score step should have been defined in the module assert 'score' in p.stepIds # MAS module should automatically have methods bound assert callable(p.score)
def test_publish_sklearn_again(self): from sasctl.tasks import publish_model from sasctl.services import model_repository as mr model = mr.get_model(SCIKIT_MODEL_NAME, PROJECT_NAME) # Should not be able to republish the model by default with pytest.raises(RuntimeError): publish_model(model, 'maslocal', max_retries=100) # Publish should succeed with replace flag p = publish_model(model, 'maslocal', max_retries=100, replace=True) # Score step should have been defined in the module assert 'score' in p.stepIds # MAS module should automatically have methods bound assert callable(p.score)
def test_get_model_by_name(): """If multiple models exist with the same name, a warning should be raised. From https://github.com/sassoftware/python-sasctl/issues/92 """ MODEL_NAME = 'Test Model' # Create a dummy session with mock.patch('sasctl.core.requests.Session.request'): current_session('example.com', 'user', 'password') mock_responses = [ # First response is for list_items/list_models [{ 'id': 12345, 'name': MODEL_NAME }, { 'id': 67890, 'name': MODEL_NAME }], # Second response is mock GET for model details { 'id': 12345, 'name': MODEL_NAME }, ] with mock.patch('sasctl._services.model_repository.ModelRepository.request' ) as request: request.side_effect = mock_responses with pytest.warns(Warning): result = mr.get_model(MODEL_NAME) assert result['id'] == 12345 assert result['name'] == MODEL_NAME
### avoid using variable names with . it will have error with DS2 inputs = table.drop('Species', axis=1) # Need one example of each var for guessing type ### can't have NaN #inputs['DEBTINC'] = .5 outputs = table.columns.to_list()[4] outputs = pd.DataFrame(columns=[str(outputs), 'P_set', 'P_vers', 'P_virg']) outputs.loc[len(outputs)] = ['virginica', 0.5, 0.5, .5] #model.predict_proba(inputs[:1]) ### DON'T DO THAT IN PRODUCTION model_exists = model_repository.get_model(modelname, refresh=False) #model_repository.delete_model(modelname) if model_exists == None: print('Creating new model') register_model( model=model, name=modelname, project=project, input=inputs, ## somehow using a pd.df bug but SASdf don't force=True) else: print('Model exists, creting new version') model_repository.delete_model_contents(modelname) register_model(model=model, name=modelname,