def save_model_manager_to_s3(model_name, model_manager, bucket=EMMAA_BUCKET_NAME): logger.info(f'Saving a model manager for {model_name} model to S3.') date_str = model_manager.date_str save_pickle_to_s3(model_manager, bucket, f'results/{model_name}/model_manager_{date_str}.pkl')
def save_to_s3(self, bucket=EMMAA_BUCKET_NAME): """Dump the model state to S3.""" date_str = make_date_str() fname = f'models/{self.name}/model_{date_str}' # Dump as pickle save_pickle_to_s3(self.stmts, bucket, key=fname + '.pkl') # Dump as json save_json_to_s3(self.stmts, bucket, key=fname + '.json')
def save_to_s3(self, bucket=EMMAA_BUCKET_NAME): """Dump the model state to S3.""" fname = f'models/{self.name}/model_{self.date_str}' # Dump as pickle save_pickle_to_s3(self.stmts, bucket, key=fname+'.pkl') # Save ids to stmt hashes mapping as json id_fname = f'papers/{self.name}/paper_ids_{self.date_str}.json' save_json_to_s3(list(self.paper_ids), bucket, key=id_fname)
def save_model_manager_to_s3(model_name, model_manager, bucket=EMMAA_BUCKET_NAME): logger.info(f'Saving a model manager for {model_name} model to S3.') date_str = model_manager.date_str model_manager.model.stmts = [] model_manager.model.assembled_stmts = [] model_manager.model.dynamic_assembled_stmts = [] save_pickle_to_s3(model_manager, bucket, f'results/{model_name}/model_manager_{date_str}.pkl')
def save_tests_to_s3(tests, bucket, key, save_format='pkl'): """Save tests in pkl, json or jsonl format.""" if save_format == 'pkl': save_pickle_to_s3(tests, bucket, key) elif save_format in ['json', 'jsonl']: if isinstance(tests, list): stmts = [test.stmt for test in tests] elif isinstance(tests, dict): stmts = [test.stmt for test in tests['tests']] stmts_json = stmts_to_json(stmts) save_json_to_s3(stmts_json, bucket, key, save_format)
def model_to_tests(model_name, upload=True, bucket=EMMAA_BUCKET_NAME): em = EmmaaModel.load_from_s3(model_name, bucket=bucket) em.run_assembly() tests = [ StatementCheckingTest(stmt) for stmt in em.assembled_stmts if all(stmt.agent_list()) ] date_str = make_date_str() test_description = ( f'These tests were generated from the {em.human_readable_name} ' f'on {date_str[:10]}') test_dict = { 'test_data': { 'description': test_description }, 'tests': tests } if upload: save_pickle_to_s3(test_dict, bucket, f'tests/{model_name}_tests_{date_str}.pkl') return test_dict