Skip to content

Commit

Permalink
show used weights
Browse files Browse the repository at this point in the history
  • Loading branch information
salmma committed Aug 7, 2024
1 parent 6d03ed1 commit 3ab308e
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div *ngIf="weightLearningForm">
<h1 mat-dialog-title>Initially learned Weights</h1>
<div mat-dialog-content>
<form [formGroup]="weightLearningForm">
<p>The learned weights are presented</p>
<div formArrayName="criteriaAndValues">
<div *ngFor="let criterion of criteriaNamesAndValues; let i = index" [formGroupName]="i">
<div *ngIf="criterion.name !== 'queue-size'">
{{ criterion.name }}:
<br>
{{ criterion.weight }}
</div>
<br>
</div>
</div>
</form>
</div>
<div mat-dialog-actions>
<button mat-button [mat-dialog-close]="data">Ok
</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Component, Inject, OnInit } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup } from '@angular/forms';
import {
MAT_DIALOG_DATA,
MatDialog,
MatDialogRef,
} from '@angular/material/dialog';
import { XmcdaCriteriaService } from 'api-nisq/services/xmcda-criteria.service';
// eslint-disable-next-line max-len
import { Criterion } from '../implementation-nisq-analyzer-qpu-selection-prioritization-dialog/implementation-nisq-analyzer-qpu-selection-prioritization-dialog.component';

@Component({
selector:
'app-implementation-nisq-analyzer-qpu-selection-initial-weights-dialog',
templateUrl:
'./implementation-nisq-analyzer-qpu-selection-initial-weights-dialog.component.html',
styleUrls: [
'./implementation-nisq-analyzer-qpu-selection-initial-weights-dialog.component.scss',
],
})
export class ImplementationNisqAnalyzerQpuSelectionInitialWeightsDialogComponent
implements OnInit {
weightLearningForm: FormGroup;
criteriaNamesAndValues: Criterion[] = [];
inputChanged = false;

constructor(
public dialogRef: MatDialogRef<
ImplementationNisqAnalyzerQpuSelectionInitialWeightsDialogComponent
>,
@Inject(MAT_DIALOG_DATA) public data: DialogData,
public dialog: MatDialog,
private formBuilder: FormBuilder,
private mcdaService: XmcdaCriteriaService
) {}

get criteriaAndValues(): AbstractControl | null {
return this.weightLearningForm.get('criteriaAndValues');
}

ngOnInit(): void {
this.onMcdaMethodChanged();
}

onNoClick(): void {
this.dialogRef.close();
}

onMcdaMethodChanged(): void {
this.criteriaNamesAndValues = [];
this.mcdaService
.getCriterionForMethod({ methodName: this.data.mcdaMethod })
.subscribe((criteriaList) => {
// then get for each criterion the name and value and store both in the map as value
criteriaList.mcdaCriterionList.forEach((criterion) => {
this.mcdaService
.getCriterionValue({
methodName: this.data.mcdaMethod,
criterionId: criterion.id,
})
.subscribe((criterionValueModel) => {
const value = criterionValueModel.valueOrValues.pop();
if (value) {
const realValue = value['real'];
this.criteriaNamesAndValues.push({
id: criterion.id,
name: criterion.name,
weight: realValue,
points: Math.round(
Number(criterionValueModel.description.subTitle)
),
});
}
this.weightLearningForm = this.formBuilder.group({
criteriaAndValues: this.formBuilder.array(
this.criteriaNamesAndValues.map((c) =>
this.formBuilder.group({
[c.name]: [c.weight],
})
)
),
});
});
});
});
}

onChangeEvent(): void {
this.inputChanged = true;
}
}

export interface DialogData {
title: string;
mcdaMethod: string;
criteriaAndValues: Criterion[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { ImplementationNisqAnalyzerQpuSelectionSensitivityAnalysisDialogComponen
import { ImplementationTokenDialogComponent } from './dialogs/implementation-token-dialog/implementation-token-dialog.component';
// eslint-disable-next-line max-len
import { ImplementationNisqAnalyzerQpuSelectionLearnedWeightsDialogComponent } from './dialogs/implementation-nisq-analyzer-qpu-selection-learned-weights-dialog/implementation-nisq-analyzer-qpu-selection-learned-weights-dialog.component';
import { ImplementationNisqAnalyzerQpuSelectionInitialWeightsDialogComponent } from './dialogs/implementation-nisq-analyzer-qpu-selection-initial-weights-dialog/implementation-nisq-analyzer-qpu-selection-initial-weights-dialog.component';

Check failure on line 49 in src/app/components/algorithms/implementation-view/implementation-view.module.ts

View workflow job for this annotation

GitHub Actions / Run linters

This line has a length of 238. Maximum allowed is 160

@NgModule({
declarations: [
Expand All @@ -61,6 +62,7 @@ import { ImplementationNisqAnalyzerQpuSelectionLearnedWeightsDialogComponent } f
ImplementationNisqAnalyzerQpuSelectionSensitivityAnalysisDialogComponent,
ImplementationTokenDialogComponent,
ImplementationNisqAnalyzerQpuSelectionLearnedWeightsDialogComponent,
ImplementationNisqAnalyzerQpuSelectionInitialWeightsDialogComponent,
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ <h3>Analysis Jobs</h3>
>
Back
</button>
<button
mat-raised-button
type="button"
color="primary"
(click)="seeInitialWeights()"
>
<span>Used Weights</span>
</button>
<button *ngIf="jobReady && analyzerResults.length !== 0 && !loadingLearnWeights && !learnedWeightsReady"
mat-raised-button
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { ImplementationNisqAnalyzerQpuSelectionLearnedWeightsDialogComponent } f
import { ChangePageGuard } from '../../../services/deactivation-guard';
// eslint-disable-next-line max-len
import { ImplementationNisqAnalyzerQpuSelectionSensitivityAnalysisDialogComponent } from '../implementation-view/dialogs/implementation-nisq-analyzer-qpu-selection-sensitivity-analysis-dialog/implementation-nisq-analyzer-qpu-selection-sensitivity-analysis-dialog.component';
import { ImplementationNisqAnalyzerQpuSelectionInitialWeightsDialogComponent } from '../implementation-view/dialogs/implementation-nisq-analyzer-qpu-selection-initial-weights-dialog/implementation-nisq-analyzer-qpu-selection-initial-weights-dialog.component';

Check failure on line 53 in src/app/components/algorithms/nisq-analyzer/nisq-analyzer.component.ts

View workflow job for this annotation

GitHub Actions / Run linters

This line has a length of 259. Maximum allowed is 160
import { NisqAnalyzerService } from './nisq-analyzer.service';

@Component({
Expand Down Expand Up @@ -752,6 +753,16 @@ export class NisqAnalyzerComponent implements OnInit {
});
}

seeInitialWeights(): void {
this.utilService.createDialog(
ImplementationNisqAnalyzerQpuSelectionInitialWeightsDialogComponent,
{
title: 'Learned Weights',
mcdaMethod: this.usedMcdaMethod,
}
);
}

executePrioritization(dialogResult): void {
this.loadingMCDAJob = true;
this.prioritizationJobReady = false;
Expand Down Expand Up @@ -864,6 +875,7 @@ export class NisqAnalyzerComponent implements OnInit {
this.dataSource = new MatTableDataSource(
this.allQpuSelectionResults
);
this.usedMcdaMethod = mcdaMethod;
this.mcdaJobSuccessful = true;
this.pollingAnalysisJobData.unsubscribe();
}
Expand Down

0 comments on commit 3ab308e

Please sign in to comment.