Skip to content

Commit

Permalink
Retrieve pattern ID by type
Browse files Browse the repository at this point in the history
  • Loading branch information
wederbn committed May 14, 2024
1 parent 882a5b8 commit d902210
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { replaceErrorCorrectionPattern } from "./correction/ErrorCorrectionPatte
import { replaceMitigationPattern } from "./mitigation/MitigationPatternHandler";
import {
attachPatternsToSuitableConstruct,
findPatternIdByName,
getSolutionForPattern,
removeAlgorithmAndAugmentationPatterns,
} from "../util/PatternUtil";
Expand Down Expand Up @@ -159,13 +160,21 @@ export async function startPatternReplacementProcess(xml) {
for (let replacementConstruct of augmentationReplacementConstructs) {
console.log("Replacing augmentation pattern: ", replacementConstruct);

let patternId = replacementConstruct.task.patternId;
if (!patternId) {
console.log(
"Pattern ID undefined. Trying to retrieve via pattern name..."
);
patternId = await findPatternIdByName(replacementConstruct.task.$type);
console.log("Retrieved pattern ID: ", patternId);
}

// retrieve solution for pattern to enable correct configuration
let concreteSolution = getSolutionForPattern(
replacementConstruct.task.patternId
);
let concreteSolution = getSolutionForPattern(patternId);
console.log("Solution: ", concreteSolution);

// TODO: load detector from solution and configure inserted task
// TODO: incorporate augmentation patterns handled above

let replacementSuccess = false;
if (replacementConstruct.task.$type === constants.CIRCUIT_CUTTING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { computeDimensionsOfSubprocess } from "../../quantme/replacement/layoute
import * as constants from "../Constants";
import { isQuantMESubprocess } from "../../quantme/utilities/Utilities";
import { PATTERN_ID, PATTERN_PREFIX } from "../Constants";
import { getQcAtlasEndpoint } from "../framework-config/config-manager";
import {
getPatternAtlasEndpoint,
getQcAtlasEndpoint,
} from "../framework-config/config-manager";
import { fetchDataFromEndpoint } from "../../../editor/util/HttpUtilities";

export function attachPatternsToSubprocess(subprocess, patterns, modeling) {
let dimensions = computeDimensionsOfSubprocess(subprocess);
Expand Down Expand Up @@ -316,3 +320,41 @@ export function getSolutionForPattern(id) {
// TODO
return undefined;
}

/**
* Retrieve the ID of a pattern with the given type from the Pattern Atlas
*
* @param patternType the type of the pattern to retrieve the ID for
*/
export async function findPatternIdByName(patternType) {
console.log("Retrieving pattern ID by pattern type: ", patternType);
let patternName = patternType.split(":")[1];
console.log("Pattern name: ", patternName);

// retrieve all available patterns
console.log(
"Retrieving patterns from URL: ",
getPatternAtlasEndpoint() + "/patterns"
);
const response = await fetchDataFromEndpoint(
getPatternAtlasEndpoint() + "/patterns"
);
console.log("Response: ", response);
let patterns = response._embedded.patternModels;
console.log("Available patterns: ", patterns);

// search pattern with given name
let filteredPatterns = patterns.filter(
(pattern) =>
patternName.toUpperCase() === pattern.name.replace(" ", "").toUpperCase()
);
console.log("Patterns with given type: ", filteredPatterns);

// take the first solution if there are multiple
if (!filteredPatterns || filteredPatterns.length < 1) {
console.warn("Unable to retrieve pattern with name: ", patternName);
return undefined;
} else {
return filteredPatterns[0].id;
}
}

0 comments on commit d902210

Please sign in to comment.