Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rimpl help #158

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions scripts/rimpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,33 @@ import {openYamlFileAsObject, saveYamlFileAs} from '../src/util/yaml';
*/
const rimplScript = async () => {
try {
const {inputPath, outputPath} = parseProcessArgument();
const impl = await openYamlFileAsObject(inputPath);
const processParams = parseProcessArgument();

if (!('graph' in impl)) {
throw new Error('No graph data found.');
}
if (processParams) {
const {inputPath, outputPath} = processParams;
const impl = await openYamlFileAsObject(inputPath);

// Lifecycle Initialize Models
const modelsHandbook = new ModelsUniverse();
impl.initialize.models.forEach((model: any) =>
modelsHandbook.writeDown(model)
);
if (!('graph' in impl)) {
throw new Error('No graph data found.');
}

// Lifecycle Computing
const ateruiComputer = new Supercomputer(impl, modelsHandbook);
const ompl = await ateruiComputer.compute();
// Lifecycle Initialize Models
const modelsHandbook = new ModelsUniverse();
impl.initialize.models.forEach((model: any) =>
modelsHandbook.writeDown(model)
);

if (!outputPath) {
console.log(JSON.stringify(ompl));
return;
}
// Lifecycle Computing
const ateruiComputer = new Supercomputer(impl, modelsHandbook);
const ompl = await ateruiComputer.compute();

await saveYamlFileAs(ompl, outputPath);
if (!outputPath) {
console.log(JSON.stringify(ompl));
return;
}

await saveYamlFileAs(ompl, outputPath);
}
} catch (error) {
console.error(error);
}
Expand Down
50 changes: 46 additions & 4 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {ArgumentConfig} from 'ts-command-line-args';

import {RimplProcessArgs} from '../types/process-args';

export const CONFIG = {
MODEL_IDS: {
BOAVIZTA_CPU: 'org.boavizta.cpu.sci',
Expand All @@ -19,13 +23,51 @@ export const CONFIG = {
TEADS_CURVE: 'teads.curve',
WATT_TIME: 'org.wattime.grid',
},
VALIDATION: {
IMPL_CLI: {
impl: String,
RIMPL: {
ARGS: {
impl: {
type: String,
optional: true,
alias: 'i',
description: 'Path to an input IMPL file.',
},
ompl: {
type: String,
optional: true,
description:
'Path to the output IMPL file where the results as saved, if none is provided it prints to stdout.',
},
format: {
type: String,
optional: true,
description:
'The output file format. default to yaml but if csv is specified then it formats the impacts as a csv file for loading into another program.',
defaultValue: 'yaml',
},
verbose: {
type: Boolean,
optional: true,
description:
'How much information to output about the calculation to aid investigation and debugging.',
},
help: {
type: Boolean,
optional: true,
alias: 'h',
description: 'Prints this usage guide.',
},
},
} as ArgumentConfig<RimplProcessArgs>,
HELP: `rimpl
-impl [path to the input impl file]
-ompl [path to the output impl file]
-format [yaml|csv]
-verbose
-help
impl: path to an input IMPL file
ompl: path to the output IMPL file where the results as saved, if none is provided it prints to stdout.
format: the output file format. default to yaml but if csv is specified then it formats the impacts as a csv file for loading into another program.
verbose: how much information to output about the calculation to aid investigation and debugging.
help: prints out the above help instruction.
`,
},
};
9 changes: 6 additions & 3 deletions src/types/process-args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export interface ImplProcessArgs {
impl: string;
ompl: string;
export interface RimplProcessArgs {
impl?: string;
ompl?: string;
format?: string;
verbose?: boolean;
help?: boolean;
}
27 changes: 17 additions & 10 deletions src/util/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import {checkIfFileIsYaml} from './yaml';

import {CONFIG, STRINGS} from '../config';

import {ImplProcessArgs} from '../types/process-args';
import {RimplProcessArgs} from '../types/process-args';

const {VALIDATION} = CONFIG;
const {IMPL_CLI} = VALIDATION;
const {RIMPL} = CONFIG;
const {ARGS, HELP} = RIMPL;

const {WRONG_CLI_ARGUMENT} = STRINGS;

/**
* Validates process arguments
* @private
*/
const validateAndParseProcessArgs = () => parse<ImplProcessArgs>(IMPL_CLI);
const validateAndParseProcessArgs = () => parse<RimplProcessArgs>(ARGS);

/**
* Prepends process path to fiven `filePath`.
Expand All @@ -33,13 +33,20 @@ const prependFullFilePath = (filePath: string) => {
* Otherwise throws error.
*/
export const parseProcessArgument = () => {
const {impl, ompl} = validateAndParseProcessArgs();
const {impl, ompl, help} = validateAndParseProcessArgs();

if (checkIfFileIsYaml(impl)) {
return {
inputPath: prependFullFilePath(impl),
...(ompl && {outputPath: prependFullFilePath(ompl)}),
};
if (help) {
console.log(HELP);
return;
}

if (impl) {
if (checkIfFileIsYaml(impl)) {
return {
inputPath: prependFullFilePath(impl),
...(ompl && {outputPath: prependFullFilePath(ompl)}),
};
}
}

throw Error(WRONG_CLI_ARGUMENT);
Expand Down