def view_model(request, model_name): """ This view displays a model and its various dependencies and metadatas """ config = Mantra.get_config() models_list = Artefact.all(settings=settings, artefacts_folder=config['models_folder']) if model_name not in models_list: raise Http404("Model does not exist") # delete trial option - catch and process if request.method == 'POST': form = DeleteTrialGroupForm(request.POST) if form.is_valid(): Trial.remove_group_hash_from_contents(settings=settings, trial_group_hash=form.cleaned_data['trial_group_hash']) form = DeleteTrialGroupForm() sys.path.append(settings.MANTRA_PROJECT_ROOT) readme_content, readme_exists = CodeBase.get_readme('%s/models/%s' % (settings.MANTRA_PROJECT_ROOT, model_name)) context = {**Mantra.find_model_metadata(model_name), 'readme_exists': readme_exists, 'readme_content': readme_content} context['files'] = CodeBase.get_files('%s/models/%s'% (settings.MANTRA_PROJECT_ROOT, model_name)) context['directories'] = CodeBase.get_directories('%s/models/%s'% (settings.MANTRA_PROJECT_ROOT, model_name)) trial_group_members, _ = Trial.get_trial_group_members(settings=settings, model_filter=model_name) context['trial_groups'] = Trial.get_all_trial_group_metadata(settings=settings, trial_group_members=trial_group_members) context['trial_groups'].sort(key=lambda item: item['time'], reverse=True) context['form'] = form return render(request, 'view_model.html', context)
def view_dataset_codebase(request, dataset_name, path): """ This view displays a dataset codebase and its various dependencies and metadatas """ config = Mantra.get_config() data_list = Artefact.all(settings=settings, artefacts_folder=config['data_folder']) if dataset_name not in data_list: raise Http404("Dataset does not exist") # delete trial option - catch and process if request.method == 'POST': form = DeleteTrialGroupForm(request.POST) if form.is_valid(): Trial.remove_group_hash_from_contents( settings=settings, trial_group_hash=form.cleaned_data['trial_group_hash']) form = DeleteTrialGroupForm() # Project readme readme_content, readme_exists = CodeBase.get_readme( '%s/data/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name)) sys.path.append(settings.MANTRA_PROJECT_ROOT) context = { **Mantra.find_dataset_metadata(dataset_name), 'readme_exists': readme_exists, 'readme_content': readme_content } context['files'] = CodeBase.get_files( '%s/data/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name)) context['directories'] = CodeBase.get_directories( '%s/data/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name)) trial_group_members, model_trials = Trial.get_trial_group_members( settings=settings, data_filter=dataset_name) context['task_list'] = Task.calculate_task_metadata(settings=settings, trials=model_trials) context['trial_groups'] = Trial.get_all_trial_group_metadata( settings=settings, trial_group_members=trial_group_members) context['trial_groups'].sort(key=lambda item: item['time'], reverse=True) context['form'] = form path = path.rstrip('/') codebase_data = CodeBase.get_code_data( blob_path='%s/data/%s/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name, path), path=path) context.update(codebase_data) return render(request, 'view_data_codebase.html', context)
def view_dataset_task(request, dataset_name, task_name): """ This view shows the dataset module page """ config = Mantra.get_config() data_list = Artefact.all(settings=settings, artefacts_folder=config['data_folder']) if dataset_name not in data_list: raise Http404("Dataset does not exist") # delete trial option - catch and process if request.method == 'POST': form = DeleteTrialGroupForm(request.POST) if form.is_valid(): Trial.remove_group_hash_from_contents(settings=settings, trial_group_hash=form.cleaned_data['trial_group_hash']) form = DeleteTrialGroupForm() # Project readme readme_content, readme_exists = CodeBase.get_readme('%s/data/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name)) sys.path.append(settings.MANTRA_PROJECT_ROOT) context = {**Mantra.find_dataset_metadata(dataset_name), 'readme_exists': readme_exists, 'readme_content': readme_content} context['files'] = CodeBase.get_files('%s/data/%s'% (settings.MANTRA_PROJECT_ROOT, dataset_name)) context['directories'] = CodeBase.get_directories('%s/data/%s'% (settings.MANTRA_PROJECT_ROOT, dataset_name)) trial_group_members, model_trials = Trial.get_trial_group_members(settings=settings, data_filter=dataset_name) task_trials = [trial for trial in model_trials if trial['task_name'] == task_name] trials_with_metadata = [] for trial in task_trials: trial.update({'time': datetime.datetime.utcfromtimestamp(int(str(trial['timestamp'])))}) try: trial['metadata'] = yaml.load(open('%s/trials/%s/trial_metadata.yml' % (settings.MANTRA_PROJECT_ROOT, trial['folder_name']), 'r').read()) trial['model_metadata'] = Mantra.find_model_metadata(trial['model_name']) if 'validation_loss' in trial['metadata']: trials_with_metadata.append(trial) except: # can't load yaml continue context['task_trials'] = trials_with_metadata context['task_trials'].sort(key=lambda item: item['metadata']['validation_loss'], reverse=False) context['task_name'] = task_name context['task_metadata'] = Mantra.find_task_metadata(task_name) context['trial_groups'] = Trial.get_all_trial_group_metadata(settings=settings, trial_group_members=trial_group_members) context['trial_groups'].sort(key=lambda item: item['time'], reverse=True) context['form'] = form return render(request, 'view_data_task.html', context)
def view_model_codebase(request, model_name, path): """ This view shows the codebase for a model """ # delete trial option - catch and process if request.method == 'POST': form = DeleteTrialGroupForm(request.POST) if form.is_valid(): Trial.remove_group_hash_from_contents(settings=settings, trial_group_hash=form.cleaned_data['trial_group_hash']) form = DeleteTrialGroupForm() config = Mantra.get_config() models_dir = os.path.join(settings.MANTRA_PROJECT_ROOT, config["models_folder"]) if os.path.isdir(models_dir): models_list = [o for o in os.listdir(models_dir) if os.path.isdir(os.path.join(models_dir, o))] else: models_list = [] if model_name not in models_list: raise Http404("Model does not exist") # Project readme readme_content, readme_exists = CodeBase.get_readme('%s/models/%s' % (settings.MANTRA_PROJECT_ROOT, model_name)) sys.path.append(settings.MANTRA_PROJECT_ROOT) context = {**Mantra.find_model_metadata(model_name), 'readme_exists': readme_exists, 'readme_content': readme_content} context['files'] = CodeBase.get_files('%s/models/%s'% (settings.MANTRA_PROJECT_ROOT, model_name)) context['directories'] = CodeBase.get_directories('%s/models/%s'% (settings.MANTRA_PROJECT_ROOT, model_name)) trial_group_members, model_trials = Trial.get_trial_group_members(settings=settings, model_filter=model_name) context['trial_groups'] = Trial.get_all_trial_group_metadata(settings=settings, trial_group_members=trial_group_members) context['trial_groups'].sort(key=lambda item: item['time'], reverse=True) context['form'] = form path = path.rstrip('/') codebase_data = CodeBase.get_code_data( blob_path='%s/models/%s/%s' % (settings.MANTRA_PROJECT_ROOT, model_name, path), path=path) context.update(codebase_data) return render(request, 'view_codebase.html', context)