analogcli 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- analogcli-0.1.4/PKG-INFO +276 -0
- analogcli-0.1.4/README.md +261 -0
- analogcli-0.1.4/pyproject.toml +67 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/__init__.py +0 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/client.py +385 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/__init__.py +0 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/compile.py +164 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/info.py +97 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/run.py +116 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/status.py +20 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/__init__.py +29 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/delete.py +22 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/info.py +66 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/list.py +82 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/logs.py +120 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/result.py +64 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/revoke.py +23 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/search.py +238 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/status.py +54 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/commands/task/wait.py +67 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/context.py +18 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/entity_tree.py +110 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/main.py +52 -0
- analogcli-0.1.4/src/anabrid/cloud/cli/utils.py +421 -0
- analogcli-0.1.4/tests/__init__.py +0 -0
- analogcli-0.1.4/tests/fixtures/lucidac.apb +0 -0
- analogcli-0.1.4/tests/fixtures/redac.apb +0 -0
- analogcli-0.1.4/tests/test_cli.py +2833 -0
- analogcli-0.1.4/tests/test_entity_tree.py +89 -0
analogcli-0.1.4/PKG-INFO
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: analogcli
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Command-line interface for the Analog Cloud system
|
|
5
|
+
Author-Email: Anabrid <info@anabrid.com>
|
|
6
|
+
Requires-Python: <4.0,>=3.11
|
|
7
|
+
Requires-Dist: click<9.0.0,>=8.1.7
|
|
8
|
+
Requires-Dist: httpx<1.0.0,>=0.25.0
|
|
9
|
+
Requires-Dist: analogcloud-common==0.1.4
|
|
10
|
+
Requires-Dist: numpy>=2.4
|
|
11
|
+
Requires-Dist: pydantic<3.0.0,>=2.0.0
|
|
12
|
+
Requires-Dist: rich<14.0.0,>=13.0.0
|
|
13
|
+
Requires-Dist: sympy>=1.14.0
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Analog Cloud CLI
|
|
17
|
+
|
|
18
|
+
Command-line interface for the Analog Cloud analog computing system.
|
|
19
|
+
|
|
20
|
+
## Overview
|
|
21
|
+
|
|
22
|
+
The Analog Cloud CLI provides a convenient command-line interface to interact with Analog Cloud's analog computing devices through the REST API. You can submit tasks, monitor their progress, and retrieve results directly from your terminal.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
1. Navigate to the CLI directory:
|
|
27
|
+
```bash
|
|
28
|
+
cd components/cli
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. Install using pip:
|
|
32
|
+
```bash
|
|
33
|
+
pip install analogcli
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
3. The CLI tool will be available as `analogcli` command after installation.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Basic Commands
|
|
41
|
+
|
|
42
|
+
The CLI connects to an Analog Cloud API server. By default, it connects to `localhost:8000`, but you can specify different host and port:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Connect to default server
|
|
46
|
+
analogcli status
|
|
47
|
+
|
|
48
|
+
# Connect to different server
|
|
49
|
+
analogcli -h 192.168.1.100 -p 8080 status
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Available Commands
|
|
53
|
+
|
|
54
|
+
#### 1. System Status
|
|
55
|
+
Get system information and connected devices:
|
|
56
|
+
```bash
|
|
57
|
+
analogcli status
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### 2. Run Tasks
|
|
61
|
+
Execute a configuration on physical LUCIDAC device:
|
|
62
|
+
```bash
|
|
63
|
+
# Basic run
|
|
64
|
+
analogcli run config.json
|
|
65
|
+
|
|
66
|
+
# With custom parameters
|
|
67
|
+
analogcli run config.json --sample-rate 20000 --op-time 0.5 --device device1
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Options:
|
|
71
|
+
- `--sample-rate`: Number of samples per second (default: 10000)
|
|
72
|
+
- `--op-time`: Integration time in seconds (default: 0.1)
|
|
73
|
+
- `--device`: Specific device ID (auto-detected if not specified)
|
|
74
|
+
|
|
75
|
+
#### 3. Simulate Tasks
|
|
76
|
+
Execute a configuration on the built-in simulator:
|
|
77
|
+
```bash
|
|
78
|
+
# Basic simulation
|
|
79
|
+
analogcli simulate config.json
|
|
80
|
+
|
|
81
|
+
# With simulator options
|
|
82
|
+
analogcli simulate config.json --k0 1000 --with-limits --op-time 1.0
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Options:
|
|
86
|
+
- `--sample-rate`: Number of samples per second (default: 10000)
|
|
87
|
+
- `--op-time`: Integration time in seconds (default: 0.1)
|
|
88
|
+
- `--k0`: Acceleration factor (choices: 1, 10, 100, 1000, 10000; default: 10000)
|
|
89
|
+
- `--with-limits`: Enable integrator capacity limits
|
|
90
|
+
- `--device`: Device context (auto-detected if not specified)
|
|
91
|
+
|
|
92
|
+
#### 4. Compile Tasks
|
|
93
|
+
Compile an ODE specification to device configuration:
|
|
94
|
+
```bash
|
|
95
|
+
# Basic compilation
|
|
96
|
+
analogcli compiler ode.json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### 5. Async submission with `--follow / --no-follow`
|
|
100
|
+
|
|
101
|
+
`compile` and `run` are interactive by default (`--follow`): the CLI
|
|
102
|
+
submits the task, polls the server, and prints logs and results in
|
|
103
|
+
place. For pipelines and long-running jobs use `--no-follow`:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Fire and forget — print only the UUID on stdout
|
|
107
|
+
TASK_ID=$(analogcli run config.json --no-follow)
|
|
108
|
+
|
|
109
|
+
# Use the id with task subcommands later
|
|
110
|
+
analogcli task wait "$TASK_ID"
|
|
111
|
+
analogcli task result "$TASK_ID" -o result.json
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
In `--no-follow` mode stdout is **strictly** the UUID; the "Task
|
|
115
|
+
submitted" notice goes to stderr so it does not corrupt pipelines.
|
|
116
|
+
|
|
117
|
+
### Task management — `analogcli task`
|
|
118
|
+
|
|
119
|
+
The `task` subcommand group inspects, awaits, and withdraws tasks
|
|
120
|
+
asynchronously. Output is TTY-aware: interactive terminals get Rich
|
|
121
|
+
panels and tables, pipes get JSON (or raw text for `task logs`).
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
analogcli task list [--state S] [--type T] [--limit N] [--offset N]
|
|
125
|
+
[--ids-only] [--format text|json]
|
|
126
|
+
analogcli task info <id> [--format text|json]
|
|
127
|
+
analogcli task status <id> [--format text|json]
|
|
128
|
+
analogcli task logs <id> [--follow] [--format text|json]
|
|
129
|
+
analogcli task result <id> [-o FILE]
|
|
130
|
+
analogcli task wait <id> [--poll-interval S] [--timeout S]
|
|
131
|
+
analogcli task revoke <id>
|
|
132
|
+
analogcli task delete <id>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- `task list` enumerates tasks visible to your API key. Use
|
|
136
|
+
`--ids-only` to emit one UUID per line for shell loops; use
|
|
137
|
+
`--format json` for a structured dump.
|
|
138
|
+
- `task info` shows the full detail record (type-specific fields for
|
|
139
|
+
compile vs run).
|
|
140
|
+
- `task status` shows the current state and the state-transition
|
|
141
|
+
history.
|
|
142
|
+
- `task logs` prints the captured log output. With `--follow` the
|
|
143
|
+
command polls every second and emits only newly appended lines until
|
|
144
|
+
the task reaches a terminal state. Off a TTY the snapshot defaults
|
|
145
|
+
to raw text so `grep` works.
|
|
146
|
+
- `task result` writes the task's result payload. Compile tasks
|
|
147
|
+
produce binary device configurations (written to `-o FILE` or to
|
|
148
|
+
binary stdout); run tasks produce JSON (pretty-printed, written to
|
|
149
|
+
`-o FILE` or stdout).
|
|
150
|
+
- `task wait` blocks until the task reaches a terminal state and
|
|
151
|
+
carries the outcome via the exit code — stdout is left empty so the
|
|
152
|
+
shell can branch on `$?` without parsing output.
|
|
153
|
+
- `task revoke` withdraws a `QUEUED` task. It does *not* abort a task
|
|
154
|
+
that is already running (the worker keeps it). The wire-level
|
|
155
|
+
endpoint remains `POST /tasks/{id}/cancel`; the CLI verb is named
|
|
156
|
+
`revoke` because that better reflects the user-visible semantic.
|
|
157
|
+
- `task delete` removes a task and its blobs. The server refuses
|
|
158
|
+
`DELETE` on an `INPROGRESS` task whose worker run is less than two
|
|
159
|
+
minutes old, to protect the worker.
|
|
160
|
+
|
|
161
|
+
#### Exit-code contract
|
|
162
|
+
|
|
163
|
+
Shell scripts can rely on the following exit codes:
|
|
164
|
+
|
|
165
|
+
| Code | Meaning |
|
|
166
|
+
|------|---------|
|
|
167
|
+
| 0 | success / `SUCCEEDED` |
|
|
168
|
+
| 1 | task `FAILED` (for `wait`) |
|
|
169
|
+
| 2 | task `CANCELLED` (for `wait`) |
|
|
170
|
+
| 3 | transport / API error (connection refused, 5xx, etc.) |
|
|
171
|
+
| 4 | state conflict — e.g. `revoke` on a non-`QUEUED` task, or `delete` inside the worker grace window (HTTP 409) |
|
|
172
|
+
| 124 | timeout (matches GNU `timeout`); emitted by `task wait --timeout S` |
|
|
173
|
+
|
|
174
|
+
Example: revoke a queued task only if it is still queued, otherwise
|
|
175
|
+
fall through to waiting on it:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
if ! analogcli task revoke "$TASK_ID" 2>/dev/null; then
|
|
179
|
+
case $? in
|
|
180
|
+
4) analogcli task wait "$TASK_ID" ;; # already running — wait it out
|
|
181
|
+
*) exit $? ;;
|
|
182
|
+
esac
|
|
183
|
+
fi
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### File Formats
|
|
187
|
+
|
|
188
|
+
#### Configuration Files (for run/simulate)
|
|
189
|
+
JSON files containing analog circuit configurations:
|
|
190
|
+
```json
|
|
191
|
+
{
|
|
192
|
+
"integrators": {
|
|
193
|
+
"int0": {"initial_value": 1.0}
|
|
194
|
+
},
|
|
195
|
+
"constants": {
|
|
196
|
+
"k1": 2.5
|
|
197
|
+
},
|
|
198
|
+
"connections": []
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### ODE Files (for compiler)
|
|
203
|
+
JSON files containing ODE specifications:
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"variables": ["x", "y"],
|
|
207
|
+
"equations": {
|
|
208
|
+
"x": "-y",
|
|
209
|
+
"y": "x"
|
|
210
|
+
},
|
|
211
|
+
"initial_conditions": {
|
|
212
|
+
"x": 1.0,
|
|
213
|
+
"y": 0.0
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Example Workflow
|
|
219
|
+
|
|
220
|
+
1. Check system status:
|
|
221
|
+
```bash
|
|
222
|
+
analogcli status
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
2. Compile an ODE to configuration:
|
|
226
|
+
```bash
|
|
227
|
+
analogcli compiler my_ode.json
|
|
228
|
+
# Save the output to compiled_config.json when prompted
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
3. Run the compiled configuration:
|
|
232
|
+
```bash
|
|
233
|
+
analogcli run compiled_config.json --sample-rate 25000 --op-time 0.2
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
4. Or simulate instead:
|
|
237
|
+
```bash
|
|
238
|
+
analogcli simulate compiled_config.json --k0 1000 --with-limits
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Environment Variables
|
|
242
|
+
|
|
243
|
+
| Variable | Description |
|
|
244
|
+
|----------|-------------|
|
|
245
|
+
| `ANALOGCLOUD_API_KEY` | API key for authentication (required) |
|
|
246
|
+
| `ANALOGCLOUD_URL` | Base URL of the Analog Cloud server |
|
|
247
|
+
|
|
248
|
+
## Development
|
|
249
|
+
|
|
250
|
+
### Running Tests
|
|
251
|
+
```bash
|
|
252
|
+
uv run pytest
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Code Formatting
|
|
256
|
+
```bash
|
|
257
|
+
uv run black .
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Dependencies
|
|
261
|
+
|
|
262
|
+
- **click**: Command-line interface framework
|
|
263
|
+
- **httpx**: HTTP client for API communication
|
|
264
|
+
- **pydantic**: Data validation using the shared models
|
|
265
|
+
- **rich**: Rich text and beautiful formatting in the terminal
|
|
266
|
+
- **analogcloud-common**: Shared models and utilities
|
|
267
|
+
|
|
268
|
+
## Error Handling
|
|
269
|
+
|
|
270
|
+
The CLI provides user-friendly error messages for common issues:
|
|
271
|
+
- Connection errors to the API server
|
|
272
|
+
- Invalid JSON files
|
|
273
|
+
- Missing files
|
|
274
|
+
- API errors with detailed messages
|
|
275
|
+
|
|
276
|
+
Progress indicators show task status during execution, and results are displayed in a formatted, readable way.
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# Analog Cloud CLI
|
|
2
|
+
|
|
3
|
+
Command-line interface for the Analog Cloud analog computing system.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Analog Cloud CLI provides a convenient command-line interface to interact with Analog Cloud's analog computing devices through the REST API. You can submit tasks, monitor their progress, and retrieve results directly from your terminal.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
1. Navigate to the CLI directory:
|
|
12
|
+
```bash
|
|
13
|
+
cd components/cli
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
2. Install using pip:
|
|
17
|
+
```bash
|
|
18
|
+
pip install analogcli
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
3. The CLI tool will be available as `analogcli` command after installation.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Basic Commands
|
|
26
|
+
|
|
27
|
+
The CLI connects to an Analog Cloud API server. By default, it connects to `localhost:8000`, but you can specify different host and port:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Connect to default server
|
|
31
|
+
analogcli status
|
|
32
|
+
|
|
33
|
+
# Connect to different server
|
|
34
|
+
analogcli -h 192.168.1.100 -p 8080 status
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Available Commands
|
|
38
|
+
|
|
39
|
+
#### 1. System Status
|
|
40
|
+
Get system information and connected devices:
|
|
41
|
+
```bash
|
|
42
|
+
analogcli status
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### 2. Run Tasks
|
|
46
|
+
Execute a configuration on physical LUCIDAC device:
|
|
47
|
+
```bash
|
|
48
|
+
# Basic run
|
|
49
|
+
analogcli run config.json
|
|
50
|
+
|
|
51
|
+
# With custom parameters
|
|
52
|
+
analogcli run config.json --sample-rate 20000 --op-time 0.5 --device device1
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
- `--sample-rate`: Number of samples per second (default: 10000)
|
|
57
|
+
- `--op-time`: Integration time in seconds (default: 0.1)
|
|
58
|
+
- `--device`: Specific device ID (auto-detected if not specified)
|
|
59
|
+
|
|
60
|
+
#### 3. Simulate Tasks
|
|
61
|
+
Execute a configuration on the built-in simulator:
|
|
62
|
+
```bash
|
|
63
|
+
# Basic simulation
|
|
64
|
+
analogcli simulate config.json
|
|
65
|
+
|
|
66
|
+
# With simulator options
|
|
67
|
+
analogcli simulate config.json --k0 1000 --with-limits --op-time 1.0
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Options:
|
|
71
|
+
- `--sample-rate`: Number of samples per second (default: 10000)
|
|
72
|
+
- `--op-time`: Integration time in seconds (default: 0.1)
|
|
73
|
+
- `--k0`: Acceleration factor (choices: 1, 10, 100, 1000, 10000; default: 10000)
|
|
74
|
+
- `--with-limits`: Enable integrator capacity limits
|
|
75
|
+
- `--device`: Device context (auto-detected if not specified)
|
|
76
|
+
|
|
77
|
+
#### 4. Compile Tasks
|
|
78
|
+
Compile an ODE specification to device configuration:
|
|
79
|
+
```bash
|
|
80
|
+
# Basic compilation
|
|
81
|
+
analogcli compiler ode.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### 5. Async submission with `--follow / --no-follow`
|
|
85
|
+
|
|
86
|
+
`compile` and `run` are interactive by default (`--follow`): the CLI
|
|
87
|
+
submits the task, polls the server, and prints logs and results in
|
|
88
|
+
place. For pipelines and long-running jobs use `--no-follow`:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Fire and forget — print only the UUID on stdout
|
|
92
|
+
TASK_ID=$(analogcli run config.json --no-follow)
|
|
93
|
+
|
|
94
|
+
# Use the id with task subcommands later
|
|
95
|
+
analogcli task wait "$TASK_ID"
|
|
96
|
+
analogcli task result "$TASK_ID" -o result.json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
In `--no-follow` mode stdout is **strictly** the UUID; the "Task
|
|
100
|
+
submitted" notice goes to stderr so it does not corrupt pipelines.
|
|
101
|
+
|
|
102
|
+
### Task management — `analogcli task`
|
|
103
|
+
|
|
104
|
+
The `task` subcommand group inspects, awaits, and withdraws tasks
|
|
105
|
+
asynchronously. Output is TTY-aware: interactive terminals get Rich
|
|
106
|
+
panels and tables, pipes get JSON (or raw text for `task logs`).
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
analogcli task list [--state S] [--type T] [--limit N] [--offset N]
|
|
110
|
+
[--ids-only] [--format text|json]
|
|
111
|
+
analogcli task info <id> [--format text|json]
|
|
112
|
+
analogcli task status <id> [--format text|json]
|
|
113
|
+
analogcli task logs <id> [--follow] [--format text|json]
|
|
114
|
+
analogcli task result <id> [-o FILE]
|
|
115
|
+
analogcli task wait <id> [--poll-interval S] [--timeout S]
|
|
116
|
+
analogcli task revoke <id>
|
|
117
|
+
analogcli task delete <id>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
- `task list` enumerates tasks visible to your API key. Use
|
|
121
|
+
`--ids-only` to emit one UUID per line for shell loops; use
|
|
122
|
+
`--format json` for a structured dump.
|
|
123
|
+
- `task info` shows the full detail record (type-specific fields for
|
|
124
|
+
compile vs run).
|
|
125
|
+
- `task status` shows the current state and the state-transition
|
|
126
|
+
history.
|
|
127
|
+
- `task logs` prints the captured log output. With `--follow` the
|
|
128
|
+
command polls every second and emits only newly appended lines until
|
|
129
|
+
the task reaches a terminal state. Off a TTY the snapshot defaults
|
|
130
|
+
to raw text so `grep` works.
|
|
131
|
+
- `task result` writes the task's result payload. Compile tasks
|
|
132
|
+
produce binary device configurations (written to `-o FILE` or to
|
|
133
|
+
binary stdout); run tasks produce JSON (pretty-printed, written to
|
|
134
|
+
`-o FILE` or stdout).
|
|
135
|
+
- `task wait` blocks until the task reaches a terminal state and
|
|
136
|
+
carries the outcome via the exit code — stdout is left empty so the
|
|
137
|
+
shell can branch on `$?` without parsing output.
|
|
138
|
+
- `task revoke` withdraws a `QUEUED` task. It does *not* abort a task
|
|
139
|
+
that is already running (the worker keeps it). The wire-level
|
|
140
|
+
endpoint remains `POST /tasks/{id}/cancel`; the CLI verb is named
|
|
141
|
+
`revoke` because that better reflects the user-visible semantic.
|
|
142
|
+
- `task delete` removes a task and its blobs. The server refuses
|
|
143
|
+
`DELETE` on an `INPROGRESS` task whose worker run is less than two
|
|
144
|
+
minutes old, to protect the worker.
|
|
145
|
+
|
|
146
|
+
#### Exit-code contract
|
|
147
|
+
|
|
148
|
+
Shell scripts can rely on the following exit codes:
|
|
149
|
+
|
|
150
|
+
| Code | Meaning |
|
|
151
|
+
|------|---------|
|
|
152
|
+
| 0 | success / `SUCCEEDED` |
|
|
153
|
+
| 1 | task `FAILED` (for `wait`) |
|
|
154
|
+
| 2 | task `CANCELLED` (for `wait`) |
|
|
155
|
+
| 3 | transport / API error (connection refused, 5xx, etc.) |
|
|
156
|
+
| 4 | state conflict — e.g. `revoke` on a non-`QUEUED` task, or `delete` inside the worker grace window (HTTP 409) |
|
|
157
|
+
| 124 | timeout (matches GNU `timeout`); emitted by `task wait --timeout S` |
|
|
158
|
+
|
|
159
|
+
Example: revoke a queued task only if it is still queued, otherwise
|
|
160
|
+
fall through to waiting on it:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
if ! analogcli task revoke "$TASK_ID" 2>/dev/null; then
|
|
164
|
+
case $? in
|
|
165
|
+
4) analogcli task wait "$TASK_ID" ;; # already running — wait it out
|
|
166
|
+
*) exit $? ;;
|
|
167
|
+
esac
|
|
168
|
+
fi
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### File Formats
|
|
172
|
+
|
|
173
|
+
#### Configuration Files (for run/simulate)
|
|
174
|
+
JSON files containing analog circuit configurations:
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"integrators": {
|
|
178
|
+
"int0": {"initial_value": 1.0}
|
|
179
|
+
},
|
|
180
|
+
"constants": {
|
|
181
|
+
"k1": 2.5
|
|
182
|
+
},
|
|
183
|
+
"connections": []
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### ODE Files (for compiler)
|
|
188
|
+
JSON files containing ODE specifications:
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"variables": ["x", "y"],
|
|
192
|
+
"equations": {
|
|
193
|
+
"x": "-y",
|
|
194
|
+
"y": "x"
|
|
195
|
+
},
|
|
196
|
+
"initial_conditions": {
|
|
197
|
+
"x": 1.0,
|
|
198
|
+
"y": 0.0
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Example Workflow
|
|
204
|
+
|
|
205
|
+
1. Check system status:
|
|
206
|
+
```bash
|
|
207
|
+
analogcli status
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
2. Compile an ODE to configuration:
|
|
211
|
+
```bash
|
|
212
|
+
analogcli compiler my_ode.json
|
|
213
|
+
# Save the output to compiled_config.json when prompted
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
3. Run the compiled configuration:
|
|
217
|
+
```bash
|
|
218
|
+
analogcli run compiled_config.json --sample-rate 25000 --op-time 0.2
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
4. Or simulate instead:
|
|
222
|
+
```bash
|
|
223
|
+
analogcli simulate compiled_config.json --k0 1000 --with-limits
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Environment Variables
|
|
227
|
+
|
|
228
|
+
| Variable | Description |
|
|
229
|
+
|----------|-------------|
|
|
230
|
+
| `ANALOGCLOUD_API_KEY` | API key for authentication (required) |
|
|
231
|
+
| `ANALOGCLOUD_URL` | Base URL of the Analog Cloud server |
|
|
232
|
+
|
|
233
|
+
## Development
|
|
234
|
+
|
|
235
|
+
### Running Tests
|
|
236
|
+
```bash
|
|
237
|
+
uv run pytest
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Code Formatting
|
|
241
|
+
```bash
|
|
242
|
+
uv run black .
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Dependencies
|
|
246
|
+
|
|
247
|
+
- **click**: Command-line interface framework
|
|
248
|
+
- **httpx**: HTTP client for API communication
|
|
249
|
+
- **pydantic**: Data validation using the shared models
|
|
250
|
+
- **rich**: Rich text and beautiful formatting in the terminal
|
|
251
|
+
- **analogcloud-common**: Shared models and utilities
|
|
252
|
+
|
|
253
|
+
## Error Handling
|
|
254
|
+
|
|
255
|
+
The CLI provides user-friendly error messages for common issues:
|
|
256
|
+
- Connection errors to the API server
|
|
257
|
+
- Invalid JSON files
|
|
258
|
+
- Missing files
|
|
259
|
+
- API errors with detailed messages
|
|
260
|
+
|
|
261
|
+
Progress indicators show task status during execution, and results are displayed in a formatted, readable way.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"pdm-backend",
|
|
4
|
+
]
|
|
5
|
+
build-backend = "pdm.backend"
|
|
6
|
+
|
|
7
|
+
[tool.pytest.ini_options]
|
|
8
|
+
testpaths = [
|
|
9
|
+
"tests",
|
|
10
|
+
]
|
|
11
|
+
python_files = [
|
|
12
|
+
"test_*.py",
|
|
13
|
+
]
|
|
14
|
+
python_classes = [
|
|
15
|
+
"Test*",
|
|
16
|
+
]
|
|
17
|
+
python_functions = [
|
|
18
|
+
"test_*",
|
|
19
|
+
]
|
|
20
|
+
addopts = "-v --tb=short"
|
|
21
|
+
|
|
22
|
+
[tool.black]
|
|
23
|
+
line-length = 88
|
|
24
|
+
target-version = [
|
|
25
|
+
"py313",
|
|
26
|
+
]
|
|
27
|
+
include = "\\.pyi?$"
|
|
28
|
+
extend-exclude = "/(\n # directories\n \\.eggs\n | \\.git\n | \\.hg\n | \\.mypy_cache\n | \\.tox\n | \\.venv\n | build\n | dist\n)/\n"
|
|
29
|
+
|
|
30
|
+
[tool.pdm.build]
|
|
31
|
+
includes = [
|
|
32
|
+
"src/anabrid",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[tool.uv.sources.analogcloud-common]
|
|
36
|
+
path = "../common"
|
|
37
|
+
editable = true
|
|
38
|
+
|
|
39
|
+
[project]
|
|
40
|
+
authors = [
|
|
41
|
+
{ name = "Anabrid", email = "info@anabrid.com" },
|
|
42
|
+
]
|
|
43
|
+
requires-python = "<4.0,>=3.11"
|
|
44
|
+
dependencies = [
|
|
45
|
+
"click<9.0.0,>=8.1.7",
|
|
46
|
+
"httpx<1.0.0,>=0.25.0",
|
|
47
|
+
"analogcloud-common == 0.1.4",
|
|
48
|
+
"numpy>=2.4",
|
|
49
|
+
"pydantic<3.0.0,>=2.0.0",
|
|
50
|
+
"rich<14.0.0,>=13.0.0",
|
|
51
|
+
"sympy>=1.14.0",
|
|
52
|
+
]
|
|
53
|
+
name = "analogcli"
|
|
54
|
+
version = "0.1.4"
|
|
55
|
+
description = "Command-line interface for the Analog Cloud system"
|
|
56
|
+
readme = "README.md"
|
|
57
|
+
|
|
58
|
+
[project.scripts]
|
|
59
|
+
analogcli = "anabrid.cloud.cli.main:cli"
|
|
60
|
+
|
|
61
|
+
[dependency-groups]
|
|
62
|
+
dev = [
|
|
63
|
+
"pytest<8.0.0,>=7.0.0",
|
|
64
|
+
"pytest-asyncio<1.0.0,>=0.21.0",
|
|
65
|
+
"pytest-mock<4.0.0,>=3.12.0",
|
|
66
|
+
"black<24.0.0,>=23.0.0",
|
|
67
|
+
]
|
|
File without changes
|