Skip to content

Commit

Permalink
update order of pattern replacement (#159)
Browse files Browse the repository at this point in the history
* update order of pattern replacement

* fix test
  • Loading branch information
LaviniaStiliadou authored May 23, 2024
1 parent a679cb1 commit 8021f7c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,55 +81,6 @@ export async function startPatternReplacementProcess(xml) {
// Mitigation have to be handled first since cutting inserts tasks after them
// if the general pattern is attached then we add it to the elements to delete
for (let replacementConstruct of containedPatterns) {
if (replacementConstruct.task.$type === constants.PATTERN) {
const pattern = elementRegistry.get(replacementConstruct.task.id);
patterns.push(pattern);
}
if (
replacementConstruct.task.$type === constants.READOUT_ERROR_MITIGATION ||
replacementConstruct.task.$type === constants.GATE_ERROR_MITIGATION
) {
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 matchingDetectorMap = await getSolutionForPattern(patternId);
console.log(
"matchingDetectorMap for pattern: ",
matchingDetectorMap,
patternId
);

let { replaced, flows, pattern } = await replaceMitigationPattern(
replacementConstruct.task,
replacementConstruct.parent,
modeler,
matchingDetectorMap
);
allFlow = allFlow.concat(flows);
patterns.push(pattern);
modeling.removeElements(flows);
if (!replaced) {
console.log(
"Replacement of Pattern with Id " +
replacementConstruct.task.id +
" failed. Aborting process!"
);
return {
status: "failed",
cause:
"Replacement of Pattern with Id " +
replacementConstruct.task.id +
" failed. Aborting process!",
};
}
}
if (
constants.WARM_STARTING_PATTERNS.includes(replacementConstruct.task.$type)
) {
Expand Down Expand Up @@ -178,8 +129,6 @@ export async function startPatternReplacementProcess(xml) {

let replacementConstructs = containedPatterns.filter(
(construct) =>
construct.task.$type !== constants.READOUT_ERROR_MITIGATION &&
construct.task.$type !== constants.GATE_ERROR_MITIGATION &&
construct.task.$type !== constants.PATTERN &&
!constants.WARM_STARTING_PATTERNS.includes(construct.task.$type)
);
Expand Down Expand Up @@ -214,6 +163,39 @@ export async function startPatternReplacementProcess(xml) {
);

let replacementSuccess = false;
if (
replacementConstruct.task.$type === constants.READOUT_ERROR_MITIGATION ||
replacementConstruct.task.$type === constants.GATE_ERROR_MITIGATION
) {
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 matchingDetectorMap = await getSolutionForPattern(patternId);
console.log(
"matchingDetectorMap for pattern: ",
matchingDetectorMap,
patternId
);

let { replaced, flows, pattern } = await replaceMitigationPattern(
replacementConstruct.task,
replacementConstruct.parent,
modeler,
matchingDetectorMap
);
allFlow = allFlow.concat(flows);
patterns.push(pattern);
modeling.removeElements(flows);
replacementSuccess = replaced;
}

if (replacementConstruct.task.$type === constants.CIRCUIT_CUTTING) {
let { replaced, flows, pattern } = await replaceCuttingPattern(
replacementConstruct.task,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe("Test the PatternTransformator of the Pattern extension.", function ()
chai.expect(element.incoming.length).to.equal(1);
chai
.expect(element.incoming[0].source.type)
.to.equal(QUANTUM_CIRCUIT_EXECUTION_TASK);
chai.expect(element.outgoing.length).to.equal(1);
.to.equal(READOUT_ERROR_MITIGATION_TASK);
chai
.expect(element.outgoing[0].target.type)
.to.equal(READOUT_ERROR_MITIGATION_TASK);
.to.equal(RESULT_EVALUATION_TASK);
chai.expect(element.outgoing.length).to.equal(1);
chai
.expect(element.businessObject.cuttingMethod)
.to.equal("knitting toolbox");
Expand All @@ -76,11 +76,11 @@ describe("Test the PatternTransformator of the Pattern extension.", function ()
chai.expect(element.incoming.length).to.equal(1);
chai
.expect(element.incoming[0].source.type)
.to.equal(CUTTING_RESULT_COMBINATION_TASK);
.to.equal(QUANTUM_CIRCUIT_EXECUTION_TASK);
chai.expect(element.outgoing.length).to.equal(1);
chai
.expect(element.outgoing[0].target.type)
.to.equal(RESULT_EVALUATION_TASK);
.to.equal(CUTTING_RESULT_COMBINATION_TASK);
}
console.log("Pattern test terminated!");

Expand Down

0 comments on commit 8021f7c

Please sign in to comment.