Skip to content

Commit

Permalink
Quantum hardware selection (#164)
Browse files Browse the repository at this point in the history
* add flag

* fix transformation

* fix lint

* fix for hwselect

* add script to hwselection

* fix issues

* fix script

---------

Co-authored-by: LaviniaStiliadou <livia_16@live.de>
Co-authored-by: mbeisel <beiselmn@gmail.com>
  • Loading branch information
3 people authored Nov 29, 2024
1 parent d859d63 commit 1cd07f0
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ export function attachPatternsToSuitableConstruct(
construct.y + construct.height,
construct
);
console.log("added cutting");
console.log("added hardware selection");
}

if (
consts.BEHAVIORAL_PATTERNS.includes(patternType) &&
patternType !== consts.QUANTUM_HARDWARE_SELECTION &&
type === "bpmn:SubProcess"
) {
createPattern(
Expand Down Expand Up @@ -334,6 +335,7 @@ export function removeAlgorithmAndAugmentationPatterns(
modeling,
elementRegistry
) {
console.log(patterns);
for (let i = 0; i < patterns.length; i++) {
let hostFlowElements = patterns[i].attachedToRef.flowElements;

Expand Down Expand Up @@ -565,6 +567,7 @@ export function wrapExecutionTaskIntoSubprocess(
subprocess,
{}
);

modeling.connect(startEvent, copiedTask, {
type: "bpmn:SequenceFlow",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const MAXIMUM_NUM_SUBCIRCUITS = "maxNumSubCircuits";
export const AUTOMATED_SELECTION = "automatedSelection";
export const ERROR_CORRECTION_METHOD = "errorCorrectionMethod";
export const WARM_STARTING_PATTERN = "warmStartingPattern";
export const QRM_REPLACEMENT = "replacementSubprocess";

export const EXECUTION_RESULT = "executionResult";
export const EVALUATION_RESULT = "evaluationResult";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ export function AutomatedSelectionEntry({ element }) {
/>
);
}

export function CalibrationMethodEntry({ element }) {
const modeling = useService("modeling");
const translate =
Expand Down Expand Up @@ -1736,3 +1737,33 @@ export function RequirementsEntry({ element }) {
/>
);
}

export function QrmReplacementEntry({ element }) {
const modeling = useService("modeling");
const translate =
useService("translate") ||
function (str) {
return str;
};
const debounce = useService("debounceInput");

const getValue = function () {
return element.businessObject.replacementSubprocess;
};

const setValue = function (newValue) {
return modeling.updateProperties(element, {
replacementSubprocess: newValue,
});
};

return (
<CheckboxEntry
id={consts.QRM_REPLACEMENT}
label={translate("QRM Replacement")}
getValue={getValue}
setValue={setValue}
debounce={debounce}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
ErrorCorrectionMethodEntry,
WarmStartingPatternEntry,
RequirementsEntry,
QrmReplacementEntry,
} from "./QuantMEPropertyEntries";

/**
Expand Down Expand Up @@ -277,6 +278,12 @@ export function HardwareSelectionSubprocessProperties(element) {
component: AutomatedSelectionEntry,
isEdited: isTextFieldEntryEdited,
},
{
id: consts.QRM_REPLACEMENT,
element,
component: QrmReplacementEntry,
isEdited: isTextFieldEntryEdited,
},
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export async function startQuantmeReplacementProcess(
let moddle = modeler.get("moddle");

// get root element of the current diagram
const definitions = modeler.getDefinitions();
const rootElement = getRootProcess(definitions);
let definitions = modeler.getDefinitions();
let rootElement = getRootProcess(definitions);

console.log(rootElement);
if (typeof rootElement === "undefined") {
Expand All @@ -71,13 +71,50 @@ export async function startQuantmeReplacementProcess(

// get all QuantME modeling constructs from the process
let replacementConstructs = getQuantMETasks(rootElement, elementRegistry);
console.log(replacementConstructs);
for (let replacementConstruct of replacementConstructs) {
if (
replacementConstruct.task.$type ===
constants.QUANTUM_HARDWARE_SELECTION_SUBPROCESS
) {
console.log("Transforming QuantumHardwareSelectionSubprocess...");
let replacementSuccess = await replaceHardwareSelectionSubprocess(
replacementConstruct.task,
replacementConstruct.parent,
modeler,
endpointConfig.nisqAnalyzerEndpoint,
endpointConfig.transformationFrameworkEndpoint,
endpointConfig.camundaEndpoint
);
if (!replacementSuccess) {
console.log(
"Replacement of QuantME modeling construct with Id " +
replacementConstruct.task.id +
" failed. Aborting process!"
);
return {
status: "failed",
cause:
"Replacement of QuantME modeling construct with Id " +
replacementConstruct.task.id +
" failed. Aborting process!",
};
}
}
}

definitions = modeler.getDefinitions();
rootElement = getRootProcess(definitions);
layout(modeling, elementRegistry, rootElement);
updated_xml = await getXml(modeler);
replacementConstructs = getQuantMETasks(rootElement, elementRegistry);
console.log(
"Process contains " +
replacementConstructs.length +
" QuantME modeling constructs to replace..."
);
if (!replacementConstructs || !replacementConstructs.length) {
return { status: "transformed", xml: xml };
return { status: "transformed", xml: updated_xml };
}

addQProvEndpoint(rootElement, elementRegistry, modeling, moddle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export async function replaceHardwareSelectionSubprocess(
let moddle = modeler.get("moddle");

const automatedSelection = subprocess.automatedSelection;
const replacementSubprocess = subprocess.$attrs.replacementSubprocess;
console.log(elementRegistry.get(subprocess.id));
const replacementSubprocess = subprocess.replacementSubprocess;

// replace QuantumHardwareSelectionSubprocess with traditional subprocess
let element = bpmnReplace.replaceElement(elementRegistry.get(subprocess.id), {
Expand All @@ -66,6 +67,7 @@ export async function replaceHardwareSelectionSubprocess(
providers: undefined,
simulatorsAllowed: undefined,
automatedSelection: undefined,
replacementSubprocess: undefined,
});

console.log(element.businessObject.$attrs["quantme:replacementSubprocess"]);
Expand Down Expand Up @@ -254,6 +256,46 @@ export async function replaceHardwareSelectionSubprocess(
return true;
}
} else {
console.log(element);
// if the subprocess does not contain any children then the subprocess is invalid
if (element.children === undefined) {
return false;
}
// retrieve the first start event
let startEvent = element.children.filter(
(child) => child.type === "bpmn:StartEvent"
)[0];
console.log(startEvent);
if (startEvent === undefined) {
return false;
}

let scriptTask = modeling.createShape(
{ type: "bpmn:ScriptTask" },
{ x: 50, y: 50 },
element,
{}
);
scriptTask.businessObject.name = "Select Quantum Device";
scriptTask.businessObject.scriptFormat = "groovy";
scriptTask.businessObject.script = `println "selectDevice";`;
scriptTask.businessObject.asyncBefore = true;
let flows = [];
startEvent.outgoing.forEach((flow) => {
flows.push(flow);
modeling.connect(scriptTask, elementRegistry.get(flow.target.id), {
type: "bpmn:SequenceFlow",
});
});
for (let i = 0; i < flows.length; i++) {
let flow = elementRegistry.get(flows[i].id);
modeling.removeConnection(flow);
}
modeling.connect(startEvent, scriptTask, {
type: "bpmn:SequenceFlow",
});
console.log("finished tran");

return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"name": "automatedSelection",
"isAttr": true,
"type": "Boolean"
},
{
"name": "replacementSubprocess",
"isAttr": true,
"type": "Boolean"
}
]
},
Expand Down
6 changes: 6 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1cd07f0

Please sign in to comment.