asp-chef-cli 0.5.4__tar.gz → 0.5.5__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.
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/PKG-INFO +1 -1
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/server/routers/dumbo.py +66 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/pyproject.toml +1 -1
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/LICENSE +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/README.md +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/__init__.py +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/__main__.py +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/cli.py +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/server/__init__.py +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/server/dependencies.py +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/server/main.py +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/server/routers/__init__.py +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/server/routers/clingo.py +0 -0
- {asp_chef_cli-0.5.4 → asp_chef_cli-0.5.5}/asp_chef_cli/server/routers/opa.py +0 -0
|
@@ -228,6 +228,72 @@ async def _(json):
|
|
|
228
228
|
return {"models": models}
|
|
229
229
|
|
|
230
230
|
|
|
231
|
+
pasta_process: Final[Dict[str, Optional[subprocess.Popen]]] = defaultdict(lambda: None)
|
|
232
|
+
pasta_path: Final[str | None] = shutil.which("pastasolver")
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def pasta_terminate(uuid):
|
|
236
|
+
if pasta_process[uuid] is not None:
|
|
237
|
+
pasta_process[uuid].kill()
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
@endpoint(router, "/pasta/")
|
|
241
|
+
async def _(json):
|
|
242
|
+
global pasta_process
|
|
243
|
+
|
|
244
|
+
uuid = json["uuid"]
|
|
245
|
+
program = json["program"]
|
|
246
|
+
output_predicate = json["output_predicate"] or "__bounds__"
|
|
247
|
+
bound_multiplier = 0
|
|
248
|
+
try:
|
|
249
|
+
bound_multiplier = int(json["bound_multiplier"])
|
|
250
|
+
bound_multiplier = min(max(bound_multiplier, 0), 1_000_000)
|
|
251
|
+
except ValueError:
|
|
252
|
+
bound_multiplier = 0
|
|
253
|
+
|
|
254
|
+
timeout = json["timeout"]
|
|
255
|
+
if type(timeout) is not int or timeout < 1 or timeout >= 24 * 60 * 60:
|
|
256
|
+
timeout = 5
|
|
257
|
+
|
|
258
|
+
pasta_terminate(uuid)
|
|
259
|
+
|
|
260
|
+
cmd = ["/bin/timeout", str(timeout), pasta_path, "/tmp/a"]
|
|
261
|
+
pasta_process[uuid] = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
262
|
+
out, err = pasta_process[uuid].communicate(program.encode())
|
|
263
|
+
timeout_reached: Final = pasta_process[uuid].returncode == 124
|
|
264
|
+
pasta_process[uuid] = None
|
|
265
|
+
|
|
266
|
+
# report errors
|
|
267
|
+
output = out.decode()
|
|
268
|
+
lines = output.split('\n')
|
|
269
|
+
if any(line.startswith("Error") for line in lines):
|
|
270
|
+
raise ValueError(output)
|
|
271
|
+
if timeout_reached:
|
|
272
|
+
lines = [line for line in lines if not line.startswith("Sig term")]
|
|
273
|
+
|
|
274
|
+
lines = [line for line in lines if line]
|
|
275
|
+
lb, ub = None, None
|
|
276
|
+
if len(lines) == 1:
|
|
277
|
+
lb = ub = lines[0].split("Lower probability == upper probability for the query: ")[1]
|
|
278
|
+
elif len(lines) == 2:
|
|
279
|
+
lb = float(lines[0].split("Lower probability for the query: ")[1])
|
|
280
|
+
ub = float(lines[1].split("Upper probability for the query: ")[1])
|
|
281
|
+
|
|
282
|
+
if lb is None or ub is None:
|
|
283
|
+
raise ValueError("Could not parse output from PASTA solver:\n" + '\n'.join(lines))
|
|
284
|
+
|
|
285
|
+
if bound_multiplier:
|
|
286
|
+
lb = round(lb * bound_multiplier)
|
|
287
|
+
ub = round(ub * bound_multiplier)
|
|
288
|
+
else:
|
|
289
|
+
lb = f'real("{lb}")'
|
|
290
|
+
ub = f'real("{ub}")'
|
|
291
|
+
|
|
292
|
+
return {"models": [
|
|
293
|
+
[f'{output_predicate}({lb},{ub})']
|
|
294
|
+
]}
|
|
295
|
+
|
|
296
|
+
|
|
231
297
|
@endpoint(router, "/template/core-template/")
|
|
232
298
|
async def _(json):
|
|
233
299
|
if not json:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|