-
Notifications
You must be signed in to change notification settings - Fork 32
Add interactive mode to concore init CLI #510
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
Changes from 2 commits
b44e9a1
b58ce09
e17ad45
a3a2b0c
a277b6f
6c4f0f4
ec7f18a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| import os | ||
| import sys | ||
|
|
||
| from .commands.init import init_project | ||
| from .commands.init import init_project, init_project_interactive, run_wizard | ||
| from .commands.run import run_workflow | ||
| from .commands.validate import validate_workflow | ||
| from .commands.status import show_status | ||
|
|
@@ -24,12 +24,32 @@ def cli(): | |
|
|
||
|
|
||
| @cli.command() | ||
| @click.argument("name", required=True) | ||
| @click.argument("name", required=False, default=None) | ||
| @click.option("--template", default="basic", help="Template type to use") | ||
| def init(name, template): | ||
| @click.option( | ||
| "--interactive", | ||
| "-i", | ||
| is_flag=True, | ||
| help="Launch guided wizard to select node types", | ||
| ) | ||
| def init(name, template, interactive): | ||
| """Create a new concore project""" | ||
| try: | ||
| init_project(name, template, console) | ||
| if interactive: | ||
| if not name: | ||
| name = console.input("[cyan]Project name:[/cyan] ").strip() | ||
| if not name: | ||
| console.print("[red]Error:[/red] Project name is required.") | ||
| sys.exit(1) | ||
| selected = run_wizard(console) | ||
| init_project_interactive(name, selected, console) | ||
| else: | ||
| if not name: | ||
| console.print( | ||
| "[red]Error:[/red] Provide a project name or use --interactive." | ||
| ) | ||
| sys.exit(1) | ||
| init_project(name, template, console) | ||
|
Comment on lines
+27
to
+52
|
||
| except Exception as e: | ||
| console.print(f"[red]Error:[/red] {str(e)}") | ||
| sys.exit(1) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,36 @@ | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| from .metadata import write_study_metadata | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| # GraphML templates | ||||||||||||||||||||||||||||||||||||||||||||||
| # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| GRAPHML_HEADER = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||||||||||||||||||||||||||||||||||||||||||||||
| <graphml xmlns="http://graphml.graphdrawing.org/xmlns" | ||||||||||||||||||||||||||||||||||||||||||||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||||||||||||||||||||||||||||||||||||||||||
| xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd" | ||||||||||||||||||||||||||||||||||||||||||||||
| xmlns:y="http://www.yworks.com/xml/graphml"> | ||||||||||||||||||||||||||||||||||||||||||||||
| <key for="node" id="d6" yfiles.type="nodegraphics"/> | ||||||||||||||||||||||||||||||||||||||||||||||
| <key for="edge" id="d10" yfiles.type="edgegraphics"/> | ||||||||||||||||||||||||||||||||||||||||||||||
| <graph edgedefault="directed" id="1" projectName="{project_name}"> | ||||||||||||||||||||||||||||||||||||||||||||||
|
GREENRAT-K405 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||||||||
| {nodes} | ||||||||||||||||||||||||||||||||||||||||||||||
| </graph> | ||||||||||||||||||||||||||||||||||||||||||||||
| </graphml> | ||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| GRAPHML_NODE = """ <node id="n{idx}"> | ||||||||||||||||||||||||||||||||||||||||||||||
| <data key="d6"> | ||||||||||||||||||||||||||||||||||||||||||||||
| <y:ShapeNode> | ||||||||||||||||||||||||||||||||||||||||||||||
| <y:Geometry height="50" width="150" x="100" y="{y}"/> | ||||||||||||||||||||||||||||||||||||||||||||||
| <y:Fill color="{color}" opacity="1"/> | ||||||||||||||||||||||||||||||||||||||||||||||
| <y:BorderStyle color="#000000" width="1"/> | ||||||||||||||||||||||||||||||||||||||||||||||
| <y:NodeLabel>N{idx}:{filename}</y:NodeLabel> | ||||||||||||||||||||||||||||||||||||||||||||||
| <y:Shape type="rectangle"/> | ||||||||||||||||||||||||||||||||||||||||||||||
| </y:ShapeNode> | ||||||||||||||||||||||||||||||||||||||||||||||
| </data> | ||||||||||||||||||||||||||||||||||||||||||||||
| </node>""" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Single-node fallback used by non-interactive init | ||||||||||||||||||||||||||||||||||||||||||||||
| SAMPLE_GRAPHML = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||||||||||||||||||||||||||||||||||||||||||||||
| <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd" xmlns:y="http://www.yworks.com/xml/graphml"> | ||||||||||||||||||||||||||||||||||||||||||||||
| <key for="node" id="d6" yfiles.type="nodegraphics"/> | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -23,20 +53,124 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| </graphml> | ||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| SAMPLE_PYTHON = """import concore | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| concore.default_maxtime(100) | ||||||||||||||||||||||||||||||||||||||||||||||
| concore.delay = 0.02 | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| init_simtime_val = "[0.0, 0.0]" | ||||||||||||||||||||||||||||||||||||||||||||||
| val = concore.initval(init_simtime_val) | ||||||||||||||||||||||||||||||||||||||||||||||
| # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| # Per-language metadata: label, filename, node colour, source stub | ||||||||||||||||||||||||||||||||||||||||||||||
| # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| while(concore.simtime<concore.maxtime): | ||||||||||||||||||||||||||||||||||||||||||||||
| while concore.unchanged(): | ||||||||||||||||||||||||||||||||||||||||||||||
| val = concore.read(1,"data",init_simtime_val) | ||||||||||||||||||||||||||||||||||||||||||||||
| result = [v * 2 for v in val] | ||||||||||||||||||||||||||||||||||||||||||||||
| concore.write(1,"result",result,delta=0) | ||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||
| LANGUAGE_NODES = { | ||||||||||||||||||||||||||||||||||||||||||||||
| "python": { | ||||||||||||||||||||||||||||||||||||||||||||||
| "label": "Python", | ||||||||||||||||||||||||||||||||||||||||||||||
| "filename": "script.py", | ||||||||||||||||||||||||||||||||||||||||||||||
| "color": "#ffcc00", | ||||||||||||||||||||||||||||||||||||||||||||||
| "stub": ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "import concore\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "concore.default_maxtime(100)\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "concore.delay = 0.02\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 'init_val = "[0.0, 0.0]"\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| "val = concore.initval(init_val)\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "while concore.simtime < concore.maxtime:\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " while concore.unchanged():\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' val = concore.read(1, "data", init_val)\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| " result = [v * 2 for v in val]\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' concore.write(1, "result", result, delta=0)\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| "cpp": { | ||||||||||||||||||||||||||||||||||||||||||||||
| "label": "C++", | ||||||||||||||||||||||||||||||||||||||||||||||
| "filename": "script.cpp", | ||||||||||||||||||||||||||||||||||||||||||||||
| "color": "#ae85ca", | ||||||||||||||||||||||||||||||||||||||||||||||
| "stub": ( | ||||||||||||||||||||||||||||||||||||||||||||||
| '#include "concore.hpp"\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| "#include <vector>\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "int main() {\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " Concore concore;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " concore.default_maxtime(100);\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " concore.delay = 0.02;\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' std::string init_val = "[0.0, 0.0]";\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| " std::vector<double> val = concore.initval(init_val);\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " while (concore.simtime < concore.maxtime) {\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " while (concore.unchanged()) {\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' val = concore.read(1, "data", init_val);\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| " }\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' concore.write(1, "result", val, 0);\n' | ||||||||||||||||||||||||||||||||||||||||||||||
|
GREENRAT-K405 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||
| " }\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " return 0;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "}\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| "octave": { | ||||||||||||||||||||||||||||||||||||||||||||||
| "label": "Octave/MATLAB", | ||||||||||||||||||||||||||||||||||||||||||||||
| "filename": "script.m", | ||||||||||||||||||||||||||||||||||||||||||||||
| "color": "#6db3f2", | ||||||||||||||||||||||||||||||||||||||||||||||
| "stub": ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "global concore;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "import_concore;\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "concore.delay = 0.02;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "concore_default_maxtime(100);\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "init_val = '[0.0, 0.0]';\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "val = concore_initval(init_val);\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "while concore.simtime < concore.maxtime\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " while concore_unchanged()\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " val = concore_read(1, 'data', init_val);\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " end\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " result = val * 2;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " concore_write(1, 'result', result, 0);\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "end\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| "verilog": { | ||||||||||||||||||||||||||||||||||||||||||||||
| "label": "Verilog", | ||||||||||||||||||||||||||||||||||||||||||||||
| "filename": "script.v", | ||||||||||||||||||||||||||||||||||||||||||||||
| "color": "#f28c8c", | ||||||||||||||||||||||||||||||||||||||||||||||
| "stub": ( | ||||||||||||||||||||||||||||||||||||||||||||||
| '`include "concore.v"\n\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| "module script;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " // concore module provides: simtime, maxtime, readdata, writedata, unchanged\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " // data[] and datasize are global arrays filled by readdata\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " real init_val[1:0]; // [simtime, value]\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " integer i;\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " initial begin\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " concore.simtime = 0;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " // set your maxtime (or let concore.maxtime file override)\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " while (concore.simtime < 100) begin\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " while (concore.unchanged(0)) begin\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " // readdata fills concore.data[] and updates concore.simtime\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' concore.readdata(1, "data", "[0.0,0.0]");\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| " end\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " // TODO: process concore.data[0..datasize-1]\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " concore.data[0] = concore.data[0] * 2;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " concore.datasize = 1;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' concore.writedata(1, "result", 0); // delta=0\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| " end\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " $finish;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " end\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| "endmodule\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| "java": { | ||||||||||||||||||||||||||||||||||||||||||||||
| "label": "Java", | ||||||||||||||||||||||||||||||||||||||||||||||
| "filename": "Script.java", | ||||||||||||||||||||||||||||||||||||||||||||||
| "color": "#a8d8a8", | ||||||||||||||||||||||||||||||||||||||||||||||
| "stub": ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "public class Script {\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " public static void main(String[] args) throws Exception {\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " concoredocker cd = new concoredocker();\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " double maxtime = 100;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " double delay = 0.02;\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' String init_val = "[0.0, 0.0]";\n\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| " String val = cd.initval(init_val);\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " while (cd.simtime() < maxtime) {\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " while (cd.unchanged()) {\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' val = cd.read(1, "data", init_val);\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| " }\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| " // TODO: process val\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| ' cd.write(1, "result", val, 0);\n' | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| " concoredocker cd = new concoredocker();\n" | |
| " double maxtime = 100;\n" | |
| " double delay = 0.02;\n" | |
| ' String init_val = "[0.0, 0.0]";\n\n' | |
| " String val = cd.initval(init_val);\n" | |
| " while (cd.simtime() < maxtime) {\n" | |
| " while (cd.unchanged()) {\n" | |
| ' val = cd.read(1, "data", init_val);\n' | |
| " }\n" | |
| " // TODO: process val\n" | |
| ' cd.write(1, "result", val, 0);\n' | |
| " double maxtime = 100;\n" | |
| " double delay = 0.02;\n" | |
| ' String init_val = "[0.0, 0.0]";\n\n' | |
| " String val = concoredocker.initVal(init_val);\n" | |
| " while (concoredocker.getSimtime() < maxtime) {\n" | |
| " while (concoredocker.unchanged()) {\n" | |
| ' concoredocker.ReadResult result = concoredocker.read(1, "data", init_val);\n' | |
| " val = result.data;\n" | |
| " }\n" | |
| " // TODO: process val\n" | |
| ' concoredocker.write(1, "result", val, 0);\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can improve after java has been properly integrated in concore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avinxshKD has largely implemented Java version, and so our Java implementation is probably beyond the "toy" phase. What do you say, @avinxshKD?
Uh oh!
There was an error while loading. Please reload this page.