Skip to content

Commit

Permalink
start integrating runModelInShell to IEF structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcook1186 committed Aug 31, 2023
1 parent 73f2364 commit 6f74c7d
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/lib/shell-imp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { IImpactModelInterface } from '../interfaces';

Check failure on line 1 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·IImpactModelInterface·` with `IImpactModelInterface`
import { KeyValuePair } from '../../types/boavizta';

Check failure on line 2 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·KeyValuePair·}·from·'../../types/boavizta';⏎` with `KeyValuePair}·from·'../../types/boavizta';`

Check warning on line 2 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

'KeyValuePair' is defined but never used


export class ShellModel implements IImpactModelInterface {
// Defined for compatibility. Not used in TEADS.
authParams: object | undefined;
// name of the data source
name: string | undefined;

/**
* Defined for compatibility. Not used in TEADS.
*/
authenticate(authParams: object): void {
this.authParams = authParams;
}

/**
* Configures the TEADS Plugin for IEF
* @param {string} name name of the resource
* @param {Object} staticParams static parameters for the resource
* @param {number} staticParams.tdp Thermal Design Power in Watts
*/
async configure(
name: string,
staticParams: object | undefined = undefined

Check warning on line 26 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

'staticParams' is assigned a value but never used
): Promise<IImpactModelInterface> {
this.name = name;
return this;
}

/*

Check failure on line 32 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
description:
spawns a child process to run an external IMP
expects execPath to be a path to an executable with a CLI exposing two methods: --calculate and --impl
The shell command then calls the --command method passing var impl as the path to the desired impl file
params:
- impl: yaml string (impl minus top level config)
- execPath: (string) path to executable
- omplName: (string) savename for ompl file
returns:
- ompl data to stdout
- ompl data to disk as omplName.yaml
*/
private runModelInShell(observations, execPath, omplName) {
try {
const result = cp.spawnSync(execPath, ['--calculate', '--impl=' + observations]).stdout.toString();

Check failure on line 49 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Replace `.spawnSync(execPath,·['--calculate',·'--impl='·+·observations])` with `⏎········.spawnSync(execPath,·['--calculate',·'--impl='·+·observations])⏎········`
const yamlData = yaml.dump(yaml.load(result))

Check failure on line 50 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `;`
fs.writeFileSync(omplName, yamlData, 'utf8');
return yamlData

Check failure on line 52 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `;`
} catch (e) {
console.error(e)

Check failure on line 54 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `;`
}
}

async calculate(
observations: object | object[] | undefined
): Promise<object> {
if (observations === undefined) {
throw new Error('Required Parameters not provided');
}

// TODO: NEED TO CONVERT OBSERVATIONS TO YAML STRING HERE

const resultsYaml = this.runModelInShell(observations, "/usr/bin/pimpl.py", "ompl.yaml")

Check warning on line 67 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

'resultsYaml' is assigned a value but never used

Check failure on line 67 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Replace `observations,·"/usr/bin/pimpl.py",·"ompl.yaml")` with `⏎······observations,⏎······'/usr/bin/pimpl.py',⏎······'ompl.yaml'⏎····);`

Check warning on line 67 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

Check warning on line 67 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

// TODO: NEED TO PARSE YAML RETURNED FROM MODEL TO RESULTS OBJECT
// TODO: RETURN THE RESULTS OBJECT

//return results;
}

Check failure on line 73 in src/lib/shell-imp/index.ts

View workflow job for this annotation

GitHub Actions / build

Delete `⏎⏎`



/**
* Returns model identifier
*/
modelIdentifier(): string {
return 'shellModel';
}
}

0 comments on commit 6f74c7d

Please sign in to comment.