From b7aef61f208f4a2bfc7a5e1cf6c18e20f66ce7ea Mon Sep 17 00:00:00 2001 From: Marie Salm Date: Mon, 27 Nov 2023 09:50:28 +0100 Subject: [PATCH] set multiple tokens for qpu selection --- .../execute-analysis-result-request-dto.ts | 2 +- .../api-nisq/models/qpu-selection-dto.ts | 2 +- ...analyzer-qpu-selection-dialog.component.ts | 27 +++++----- ...n-nisq-analyzer-qpu-selection.component.ts | 52 ++++++++++++------- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/generated/api-nisq/models/execute-analysis-result-request-dto.ts b/generated/api-nisq/models/execute-analysis-result-request-dto.ts index 779d30d4..deb39439 100644 --- a/generated/api-nisq/models/execute-analysis-result-request-dto.ts +++ b/generated/api-nisq/models/execute-analysis-result-request-dto.ts @@ -1,5 +1,5 @@ /* tslint:disable */ export type ExecuteAnalysisResultRequestDto = { refreshToken?: string; - tokens?: Map>; + tokens?: {}; }; diff --git a/generated/api-nisq/models/qpu-selection-dto.ts b/generated/api-nisq/models/qpu-selection-dto.ts index 207927ea..877400b5 100644 --- a/generated/api-nisq/models/qpu-selection-dto.ts +++ b/generated/api-nisq/models/qpu-selection-dto.ts @@ -4,7 +4,7 @@ export type QpuSelectionDto = { circuitLanguage?: string; circuitUrl?: string; qasmCode?: string; - tokens?: Map>; + tokens?: {}; refreshToken?: string; circuitName?: string; preciseResultsPreference?: boolean; diff --git a/src/app/components/algorithms/implementation-view/dialogs/implementation-nisq-analyzer-qpu-selection-dialog/implementation-nisq-analyzer-qpu-selection-dialog.component.ts b/src/app/components/algorithms/implementation-view/dialogs/implementation-nisq-analyzer-qpu-selection-dialog/implementation-nisq-analyzer-qpu-selection-dialog.component.ts index 3237ee19..11e34066 100644 --- a/src/app/components/algorithms/implementation-view/dialogs/implementation-nisq-analyzer-qpu-selection-dialog/implementation-nisq-analyzer-qpu-selection-dialog.component.ts +++ b/src/app/components/algorithms/implementation-view/dialogs/implementation-nisq-analyzer-qpu-selection-dialog/implementation-nisq-analyzer-qpu-selection-dialog.component.ts @@ -32,7 +32,7 @@ export class ImplementationNisqAnalyzerQpuSelectionDialogComponent selectedCompilers: string[] = []; ibmqEnabled = true; - ionqEnabled = true; + ionqEnabled = false; shortWaitingTimeEnabled = false; stableExecutionResultsEnabled = false; predictionAlgorithmInDialog = 'extra_trees_regressor'; @@ -136,11 +136,11 @@ export class ImplementationNisqAnalyzerQpuSelectionDialogComponent ), }); - this.selectedVendors = ['ibmq', 'ionq']; + this.selectedVendors = ['ibmq']; for (const vendor of this.selectedVendors) { this.vendors.push(new FormControl(vendor)); } - this.setCompilerOptions(this.vendors.value); + this.setCompilerOptions(this.selectedVendors); this.predictionAlgorithm.setValue('extra_trees_regressor'); this.metaOptimizer.setValue('ada_boost_regressor'); this.maxNumberOfCompiledCircuits.setValue(5); @@ -167,7 +167,7 @@ export class ImplementationNisqAnalyzerQpuSelectionDialogComponent } updateCompilerSelection(compilerName: string, allowed: boolean): void { - if (allowed) { + if (allowed && !this.selectedCompilers.includes(compilerName)) { this.selectedCompilers.push(compilerName); } else { this.selectedCompilers = this.selectedCompilers.filter( @@ -192,7 +192,6 @@ export class ImplementationNisqAnalyzerQpuSelectionDialogComponent } setCompilerOptions(vendors: string[]): void { - debugger; const setOfAllAvailableCompilers = new Set(); for (const vendor of vendors) { this.nisqAnalyzerService @@ -201,14 +200,16 @@ export class ImplementationNisqAnalyzerQpuSelectionDialogComponent for (const availableCompiler of availableCompilers) { setOfAllAvailableCompilers.add(availableCompiler); } + setOfAllAvailableCompilers.forEach((compiler) => { + if (!this.selectedCompilers.includes(compiler)) { + this.selectedCompilers.push(compiler); + } + }); + this.compilers.clear(); + for (const compiler of setOfAllAvailableCompilers) { + this.compilers.push(new FormControl(compiler)); + } }); - setOfAllAvailableCompilers.forEach((compiler) => - this.selectedCompilers.push(compiler) - ); - this.compilers.clear(); - for (const compiler of this.selectedCompilers) { - this.compilers.push(new FormControl(compiler)); - } } } @@ -216,7 +217,6 @@ export class ImplementationNisqAnalyzerQpuSelectionDialogComponent this.ibmqEnabled = enabled; if (enabled) { this.selectedVendors.push('ibmq'); - this.setCompilerOptions(['ibmq']); } else { this.selectedVendors = this.selectedVendors.filter( (item) => item !== 'ibmq' @@ -228,7 +228,6 @@ export class ImplementationNisqAnalyzerQpuSelectionDialogComponent this.ionqEnabled = enabled; if (enabled) { this.selectedVendors.push('ionq'); - this.setCompilerOptions(['ionq']); } else { this.selectedVendors = this.selectedVendors.filter( (item) => item !== 'ionq' diff --git a/src/app/components/algorithms/implementation-view/implementation-nisq-analyzer-qpu-selection/implementation-nisq-analyzer-qpu-selection.component.ts b/src/app/components/algorithms/implementation-view/implementation-nisq-analyzer-qpu-selection/implementation-nisq-analyzer-qpu-selection.component.ts index fa0a508a..ff3d4e29 100644 --- a/src/app/components/algorithms/implementation-view/implementation-nisq-analyzer-qpu-selection/implementation-nisq-analyzer-qpu-selection.component.ts +++ b/src/app/components/algorithms/implementation-view/implementation-nisq-analyzer-qpu-selection/implementation-nisq-analyzer-qpu-selection.component.ts @@ -215,17 +215,20 @@ export class ImplementationNisqAnalyzerQpuSelectionComponent this.analyzerJob = undefined; this.jobReady = false; refreshToken = this.planqkService.getRefreshToken(); + const tokensToDeliver = this.setVendorTokens( + dialogResult.vendors, + dialogResult.ibmqToken, + dialogResult.awsToken, + dialogResult.awsSecretToken + ); + + debugger; const qpuSelectionDto: QpuSelectionDto = { allowedProviders: dialogResult.vendors, circuitLanguage: this.nisqImpl.language, circuitUrl: this.nisqImpl.fileLocation, - tokens: this.setVendorTokens( - dialogResult.vendors, - dialogResult.ibmqToken, - dialogResult.awsToken, - dialogResult.awsSecretToken - ), + tokens: tokensToDeliver, refreshToken, compilers: dialogResult.selectedCompilers, circuitName: this.nisqImpl.name, @@ -368,21 +371,32 @@ export class ImplementationNisqAnalyzerQpuSelectionComponent ibmqToken: string, awsToken: string, awsSecretToken: string - ): Map> { - const providerTokens: Map> = new Map(); - const rawTokens: Map = new Map(); - if (vendors.filter((vendor) => vendor === 'ibmq') != null) { - rawTokens.clear(); - rawTokens.set('ibmq', ibmqToken); - providerTokens.set('ibmq', rawTokens); + ): {} { + const providerTokens = new Map>(); + const rawTokensIbmq = new Map(); + const rawTokensIonq = new Map(); + debugger; + if (vendors.includes('ibmq')) { + rawTokensIbmq.set('ibmq', ibmqToken); + providerTokens.set('ibmq', rawTokensIbmq); } - if (vendors.filter((vendor) => vendor === 'ionq') != null) { - rawTokens.clear(); - rawTokens.set('awsAccessKey', awsToken); - rawTokens.set('awsSecretKey', awsSecretToken); - providerTokens.set('ionq', rawTokens); + if (vendors.includes('ionq')) { + rawTokensIonq.set('awsAccessKey', awsToken); + rawTokensIonq.set('awsSecretKey', awsSecretToken); + providerTokens.set('ionq', rawTokensIonq); } - return providerTokens; + + debugger; + // converting such that it can be delivered via HTTP + const convMap: { [props: string]: { [props: string]: string } } = {}; + providerTokens.forEach((val: Map, key: string) => { + const innerConvMap: { [props: string]: string } = {}; + val.forEach((subVal: string, subkey: string) => { + innerConvMap[subkey] = subVal; + }); + convMap[key] = innerConvMap; + }); + return convMap; } hasExecutionResult(analysisResult: QpuSelectionResultDto): void {