fix governance reqs; allow for sandboxed jupyter notebooks for testing
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { Domain, apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { DOMAINS } from '../../../connect/state/connect-workspace.store';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { CohortBuildFile, ExperimentDetail, ModelVersion } from '../../api/governance.types';
|
||||
|
||||
/** What the dialog starts with: a version's dialog passes its own domain, scenario and version. */
|
||||
export interface NotebookRunDefaults {
|
||||
domain?: Domain;
|
||||
scenario?: string;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
const SCENARIO = /^[\w-]{1,100}$/;
|
||||
|
||||
/**
|
||||
* Uploads a Jupyter notebook and runs it on a cohort build's file, optionally
|
||||
* with a registered version to try. Closes with the run once it has started.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-notebook-run-dialog',
|
||||
imports: [
|
||||
FormsModule,
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressBarModule,
|
||||
MatSelectModule,
|
||||
],
|
||||
templateUrl: './notebook-run-dialog.html',
|
||||
styleUrl: './notebook-run-dialog.scss',
|
||||
})
|
||||
export class NotebookRunDialog {
|
||||
private readonly api = inject(GovernanceApi);
|
||||
private readonly dialogRef = inject<MatDialogRef<NotebookRunDialog, ExperimentDetail>>(MatDialogRef);
|
||||
private readonly defaults = inject<NotebookRunDefaults | null>(MAT_DIALOG_DATA, { optional: true }) ?? {};
|
||||
|
||||
readonly domains = DOMAINS;
|
||||
readonly domain = signal<Domain>(this.defaults.domain ?? 'cacu');
|
||||
readonly scenario = signal(this.defaults.scenario ?? '');
|
||||
readonly version = signal<string>(this.defaults.version ?? '');
|
||||
readonly file = signal<File | null>(null);
|
||||
readonly builds = signal<CohortBuildFile[]>([]);
|
||||
readonly build = signal<CohortBuildFile | null>(null);
|
||||
readonly versions = signal<ModelVersion[]>([]);
|
||||
readonly busy = signal(false);
|
||||
readonly error = signal<string | null>(null);
|
||||
|
||||
readonly scenarioValid = computed(() => SCENARIO.test(this.scenario()));
|
||||
readonly ready = computed(() => !!this.file() && !!this.build() && this.scenarioValid() && !this.busy());
|
||||
|
||||
constructor() {
|
||||
this.loadBuilds();
|
||||
this.loadVersions();
|
||||
}
|
||||
|
||||
buildLabel(build: CohortBuildFile): string {
|
||||
const members = build.n_members ? ` · ${build.n_members} miembros` : '';
|
||||
const asOf = build.datos_as_of ? ` · datos al ${build.datos_as_of}` : '';
|
||||
return `${build.url} · ${build.source} ${build.build}${members}${asOf}`;
|
||||
}
|
||||
|
||||
sameBuild(a: CohortBuildFile | null, b: CohortBuildFile | null): boolean {
|
||||
return !!a && !!b && a.url === b.url && a.source === b.source && a.build === b.build;
|
||||
}
|
||||
|
||||
setDomain(domain: Domain): void {
|
||||
this.domain.set(domain);
|
||||
this.version.set('');
|
||||
this.loadBuilds();
|
||||
this.loadVersions();
|
||||
}
|
||||
|
||||
setScenario(scenario: string): void {
|
||||
this.scenario.set(scenario.trim());
|
||||
this.version.set('');
|
||||
this.loadVersions();
|
||||
}
|
||||
|
||||
pick(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
this.file.set(input.files?.[0] ?? null);
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
run(): void {
|
||||
const file = this.file();
|
||||
const build = this.build();
|
||||
if (!file || !build || !this.ready()) return;
|
||||
this.busy.set(true);
|
||||
this.error.set(null);
|
||||
this.api
|
||||
.runExperiment({ file, domain: this.domain(), scenario: this.scenario(), build, version: this.version() || null })
|
||||
.subscribe({
|
||||
next: (run) => this.dialogRef.close(run),
|
||||
error: (error) => {
|
||||
this.busy.set(false);
|
||||
this.error.set(apiErrorMessage(error, 'No se pudo iniciar el notebook.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private loadBuilds(): void {
|
||||
this.builds.set([]);
|
||||
this.build.set(null);
|
||||
this.api.cohortFiles(this.domain()).subscribe({
|
||||
next: ({ builds }) => {
|
||||
this.builds.set(builds);
|
||||
this.build.set(builds[0] ?? null);
|
||||
},
|
||||
error: (error) => this.error.set(apiErrorMessage(error, 'No se pudieron cargar las cohortes exportadas.')),
|
||||
});
|
||||
}
|
||||
|
||||
private loadVersions(): void {
|
||||
this.versions.set([]);
|
||||
if (!this.scenarioValid()) return;
|
||||
this.api.listModelVersions({ domain: this.domain(), scenario: this.scenario() }).subscribe({
|
||||
next: ({ model_versions }) => this.versions.set(model_versions),
|
||||
error: () => this.versions.set([]),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user