Skip to content

Commit 86fc2a1

Browse files
tothtamas28rv-auditor
authored andcommitted
Add support for some missing Booster options (runtimeverification/pyk#826)
Fixes #816 Adds * `--fallback-on` * `--interim-simplification` * `--no-post-exec-simplify` --------- Co-authored-by: devops <[email protected]>
1 parent fc38810 commit 86fc2a1

File tree

5 files changed

+89
-8
lines changed

5 files changed

+89
-8
lines changed

pyk/docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
project = 'pyk'
1010
author = 'Runtime Verification, Inc'
1111
copyright = '2024, Runtime Verification, Inc'
12-
version = '0.1.590'
13-
release = '0.1.590'
12+
version = '0.1.591'
13+
release = '0.1.591'
1414

1515
# -- General configuration ---------------------------------------------------
1616
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

pyk/package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.590
1+
0.1.591

pyk/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyk"
7-
version = "0.1.590"
7+
version = "0.1.591"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

pyk/src/pyk/kore/rpc.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,17 @@ def _get_host_and_port(pid: int) -> tuple[str, int]:
11631163
return conn.laddr
11641164

11651165

1166-
class BoosterServerArgs(KoreServerArgs):
1166+
class FallbackReason(Enum):
1167+
BRANCHING = 'Branching'
1168+
STUCK = 'Stuck'
1169+
ABORTED = 'Aborted'
1170+
1171+
1172+
class BoosterServerArgs(KoreServerArgs, total=False):
11671173
llvm_kompiled_dir: Required[str | Path]
1174+
fallback_on: Iterable[str | FallbackReason] | None
1175+
interim_simplification: int | None
1176+
no_post_exec_simplify: bool | None
11681177

11691178

11701179
class BoosterServer(KoreServer):
@@ -1173,6 +1182,10 @@ class BoosterServer(KoreServer):
11731182
_llvm_definition: Path
11741183
_llvm_dt: Path
11751184

1185+
_fallback_on: list[FallbackReason] | None
1186+
_interim_simplification: int | None
1187+
_no_post_exec_simplify: bool
1188+
11761189
def __init__(self, args: BoosterServerArgs):
11771190
self._llvm_kompiled_dir = Path(args['llvm_kompiled_dir'])
11781191

@@ -1189,6 +1202,14 @@ def __init__(self, args: BoosterServerArgs):
11891202
self._llvm_definition = self._llvm_kompiled_dir / 'definition.kore'
11901203
self._llvm_dt = self._llvm_kompiled_dir / 'dt'
11911204

1205+
if fallback_on := args.get('fallback_on'):
1206+
self._fallback_on = [FallbackReason(reason) for reason in fallback_on]
1207+
else:
1208+
self._fallback_on = None
1209+
1210+
self._interim_simplification = args.get('interim_simplification')
1211+
self._no_post_exec_simplify = bool(args.get('no_post_exec_simplify'))
1212+
11921213
if not args.get('command'):
11931214
args['command'] = 'kore-rpc-booster'
11941215

@@ -1200,9 +1221,21 @@ def _validate(self) -> None:
12001221
check_file_path(self._llvm_definition)
12011222
check_dir_path(self._llvm_dt)
12021223

1224+
if self._fallback_on is not None and not self._fallback_on:
1225+
raise ValueError("'fallback_on' must not be empty")
1226+
1227+
if self._interim_simplification and self._interim_simplification < 0:
1228+
raise ValueError(f"'interim_simplification' must not be negative, got: {self._interim_simplification}")
1229+
12031230
def _extra_args(self) -> list[str]:
12041231
res = super()._extra_args()
12051232
res += ['--llvm-backend-library', str(self._dylib)]
1233+
if self._fallback_on is not None:
1234+
res += ['--fallback-on', ','.join(reason.value for reason in self._fallback_on)]
1235+
if self._interim_simplification is not None:
1236+
res += ['--interim-simplification', str(self._interim_simplification)]
1237+
if self._no_post_exec_simplify:
1238+
res += ['--no-post-exec-simplify']
12061239
return res
12071240

12081241
def _populate_bug_report(self, bug_report: BugReport) -> None:
@@ -1217,7 +1250,6 @@ def kore_server(
12171250
definition_dir: str | Path,
12181251
module_name: str,
12191252
*,
1220-
llvm_definition_dir: Path | None = None,
12211253
port: int | None = None,
12221254
command: str | Iterable[str] | None = None,
12231255
smt_timeout: int | None = None,
@@ -1226,6 +1258,12 @@ def kore_server(
12261258
log_axioms_file: Path | None = None,
12271259
haskell_log_format: KoreExecLogFormat | None = None,
12281260
haskell_log_entries: Iterable[str] | None = None,
1261+
# booster
1262+
llvm_definition_dir: Path | None = None,
1263+
fallback_on: Iterable[str | FallbackReason] | None,
1264+
interim_simplification: int | None,
1265+
no_post_exec_simplify: bool | None,
1266+
# ---
12291267
bug_report: BugReport | None = None,
12301268
) -> KoreServer:
12311269
kore_args: KoreServerArgs = {
@@ -1242,6 +1280,12 @@ def kore_server(
12421280
'bug_report': bug_report,
12431281
}
12441282
if llvm_definition_dir:
1245-
booster_args: BoosterServerArgs = {'llvm_kompiled_dir': llvm_definition_dir, **kore_args}
1283+
booster_args: BoosterServerArgs = {
1284+
'llvm_kompiled_dir': llvm_definition_dir,
1285+
'fallback_on': fallback_on,
1286+
'interim_simplification': interim_simplification,
1287+
'no_post_exec_simplify': no_post_exec_simplify,
1288+
**kore_args,
1289+
}
12461290
return BoosterServer(booster_args)
12471291
return KoreServer(kore_args)

pyk/src/tests/integration/kore/test_kore_client.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from dataclasses import asdict
4+
from itertools import count
45
from string import Template
56
from typing import TYPE_CHECKING
67

@@ -9,6 +10,7 @@
910
from pyk.kore.parser import KoreParser
1011
from pyk.kore.prelude import BOOL, INT, TRUE, and_bool, eq_int, gt_int, int_dv, le_int
1112
from pyk.kore.rpc import (
13+
BoosterServer,
1214
BranchingResult,
1315
CutPointResult,
1416
DepthBoundResult,
@@ -30,10 +32,12 @@
3032

3133
if TYPE_CHECKING:
3234
from collections.abc import Mapping
35+
from pathlib import Path
3336
from typing import Any, Final
3437

35-
from pyk.kore.rpc import ExecuteResult, GetModelResult, KoreClient
38+
from pyk.kore.rpc import BoosterServerArgs, ExecuteResult, GetModelResult, KoreClient
3639
from pyk.kore.syntax import Pattern
40+
from pyk.testing import Kompiler
3741

3842
int_top = Top(INT)
3943
int_bottom = Bottom(INT)
@@ -372,3 +376,36 @@ def test_get_model_with_smt(
372376

373377
# Then
374378
assert actual == expected
379+
380+
381+
START_BOOSTER_SERVER_TEST_DATA: Final[tuple[dict[str, Any], ...]] = (
382+
{},
383+
{'fallback_on': ['Aborted', 'Stuck']},
384+
{'interim_simplification': 3},
385+
{'no_post_exec_simpify': True},
386+
)
387+
388+
389+
@pytest.fixture(scope='module')
390+
def imp_dir(kompile: Kompiler) -> Path:
391+
return kompile(K_FILES / 'imp.k', backend='haskell')
392+
393+
394+
@pytest.fixture(scope='module')
395+
def imp_llvm_dir(kompile: Kompiler) -> Path:
396+
return kompile(K_FILES / 'imp.k', backend='llvm', llvm_kompile_type='c')
397+
398+
399+
@pytest.mark.parametrize('args', START_BOOSTER_SERVER_TEST_DATA, ids=count())
400+
def test_start_booster_server(imp_dir: Path, imp_llvm_dir: Path, args: dict) -> None:
401+
# Given
402+
booster_args: BoosterServerArgs = {
403+
'kompiled_dir': imp_dir,
404+
'llvm_kompiled_dir': imp_llvm_dir,
405+
'module_name': 'IMP',
406+
**args,
407+
}
408+
409+
# When
410+
with BoosterServer(booster_args):
411+
pass

0 commit comments

Comments
 (0)