-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes and similfications + refactorings
- Loading branch information
Pop John
committed
Jul 4, 2024
1 parent
8f12f99
commit 204f490
Showing
15 changed files
with
132 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const express = require('express'); | ||
const { broadcastTerminal } = require('../services/websocketService'); | ||
const ALGORITHM_TYPES = require('../constants/algorithmTypesConstants'); | ||
const { executeCommand } = require('./commandExecutionFacade'); | ||
const { pruningParserInstance } = require('../parsers/pruningParser'); | ||
const { quantizationParserInstance } = require('../parsers/quantizationParser'); | ||
const { machineUnlearningParserInstance } = require('../parsers/machineUnlearningParser'); | ||
|
||
class ScriptExecutor { | ||
constructor(type, parser) { | ||
this.type = type; | ||
this.parser = parser; | ||
} | ||
|
||
execute(scriptPath, algorithm, args) { | ||
return new Promise((resolve, reject) => { | ||
this.parser.reset(); | ||
const cmd = this.buildCommand(scriptPath, algorithm, args); | ||
const pythonCmd = this.buildPythonCommand(scriptPath, algorithm, args); | ||
|
||
broadcastTerminal(pythonCmd); | ||
|
||
executeCommand( | ||
cmd, | ||
(data) => this.handleOutput(data), | ||
() => resolve(), | ||
(error) => reject(error) | ||
); | ||
}); | ||
} | ||
|
||
buildCommand(scriptPath, algorithm, args) { | ||
if (this.type === ALGORITHM_TYPES.MULTIFLOW) { | ||
return `source "${process.env.CONDA_SH_PATH}" && cd "${process.env.MACHINE_LEARNING_CORE_PATH}/multiflow" && conda activate modelsmith && python3 ${algorithm} ${args}`; | ||
} | ||
return `source "${process.env.CONDA_SH_PATH}" && conda activate modelsmith && python3 "${scriptPath}${algorithm}" ${args}`; | ||
} | ||
|
||
buildPythonCommand(scriptPath, algorithm, args) { | ||
if (this.type === ALGORITHM_TYPES.MULTIFLOW) { | ||
return `python3 ${algorithm} ${args}`; | ||
} | ||
return `python3 "${scriptPath}${algorithm}" ${args}`; | ||
} | ||
|
||
handleOutput(data) { | ||
const formattedData = data.toString(); | ||
broadcastTerminal(formattedData); | ||
this.parser.parseLine(formattedData); | ||
} | ||
} | ||
|
||
const executorFactory = { | ||
[ALGORITHM_TYPES.PRUNING]: new ScriptExecutor(ALGORITHM_TYPES.PRUNING, pruningParserInstance), | ||
[ALGORITHM_TYPES.QUANTIZATION]: new ScriptExecutor(ALGORITHM_TYPES.QUANTIZATION, quantizationParserInstance), | ||
[ALGORITHM_TYPES.MACHINE_UNLEARNING]: new ScriptExecutor( | ||
ALGORITHM_TYPES.MACHINE_UNLEARNING, | ||
machineUnlearningParserInstance | ||
), | ||
[ALGORITHM_TYPES.MULTIFLOW]: new ScriptExecutor(ALGORITHM_TYPES.MULTIFLOW, { reset: () => {}, parseLine: () => {} }) | ||
}; | ||
|
||
module.exports = module.exports = { | ||
ScriptExecutor, | ||
executorFactory | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 0 additions & 141 deletions
141
frontend/src/app/modules/algorithm-comparison/models/records-mock-data.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.