sciel 0.23.2__py3-none-any.whl
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.
- sciel/__init__.py +1 -0
- sciel/campaign/__init__.py +0 -0
- sciel/campaign/budget.py +467 -0
- sciel/campaign/identity.py +97 -0
- sciel/campaign/memory.py +298 -0
- sciel/campaign/no_regression.py +118 -0
- sciel/candidate_modules/__init__.py +239 -0
- sciel/causal/__init__.py +4 -0
- sciel/causal/estimators.py +70 -0
- sciel/causal/ledger.py +134 -0
- sciel/causal/sequential.py +102 -0
- sciel/cli/__init__.py +0 -0
- sciel/cli/live.py +144 -0
- sciel/cli/main.py +335 -0
- sciel/cli/profile.py +65 -0
- sciel/cli/start.py +189 -0
- sciel/cli/supervise.py +202 -0
- sciel/components/__init__.py +0 -0
- sciel/components/bets/__init__.py +0 -0
- sciel/components/code_novelty.py +105 -0
- sciel/components/containers.py +374 -0
- sciel/components/policy/__init__.py +0 -0
- sciel/components/policy/base.py +52 -0
- sciel/components/policy/code_embed.py +472 -0
- sciel/components/policy/controller.py +166 -0
- sciel/components/policy/mode_bandit.py +93 -0
- sciel/components/policy/mode_features.py +30 -0
- sciel/components/policy/mode_policy_mlp.py +102 -0
- sciel/components/policy/pop_features.py +29 -0
- sciel/components/policy/preset_weights.py +127 -0
- sciel/components/policy/three_head.py +167 -0
- sciel/components/policy/tilt.py +40 -0
- sciel/components/selection/__init__.py +0 -0
- sciel/components/selection/kernels.py +206 -0
- sciel/components/selection/novelty_chain.py +82 -0
- sciel/config.py +155 -0
- sciel/config_validation.py +180 -0
- sciel/culture/__init__.py +3 -0
- sciel/culture/methods.py +52 -0
- sciel/culture/repertoire.py +90 -0
- sciel/demo/__init__.py +5 -0
- sciel/demo/circles.py +54 -0
- sciel/diagnostics/__init__.py +1 -0
- sciel/diagnostics/methods_observer.py +427 -0
- sciel/diagnostics/paired_eval.py +244 -0
- sciel/engine/__init__.py +0 -0
- sciel/engine/admission.py +358 -0
- sciel/engine/assay.py +81 -0
- sciel/engine/bootstrap.py +270 -0
- sciel/engine/capacity.py +425 -0
- sciel/engine/checkpoint.py +133 -0
- sciel/engine/checkpoint_identity.py +230 -0
- sciel/engine/checkpoint_restore.py +248 -0
- sciel/engine/container_db.py +212 -0
- sciel/engine/cooperative_io.py +420 -0
- sciel/engine/db.py +259 -0
- sciel/engine/decisions.py +85 -0
- sciel/engine/determinism.py +24 -0
- sciel/engine/evaluation.py +199 -0
- sciel/engine/evaluation_timing.py +114 -0
- sciel/engine/evaluator_fifo.py +209 -0
- sciel/engine/eviction_planner.py +22 -0
- sciel/engine/factory.py +104 -0
- sciel/engine/incubator.py +201 -0
- sciel/engine/initialization.py +354 -0
- sciel/engine/journal_anchor.py +26 -0
- sciel/engine/knockout.py +91 -0
- sciel/engine/lifecycle.py +251 -0
- sciel/engine/llm/__init__.py +0 -0
- sciel/engine/llm/anthropic_api.py +78 -0
- sciel/engine/llm/claude_code.py +149 -0
- sciel/engine/llm/client.py +443 -0
- sciel/engine/llm/codex.py +368 -0
- sciel/engine/llm/codex_protocol.py +252 -0
- sciel/engine/llm/errors.py +132 -0
- sciel/engine/llm/mock.py +109 -0
- sciel/engine/llm/trace.py +133 -0
- sciel/engine/loop.py +98 -0
- sciel/engine/loop_contracts.py +105 -0
- sciel/engine/novelty.py +376 -0
- sciel/engine/observed_changes.py +404 -0
- sciel/engine/observed_schema.py +189 -0
- sciel/engine/operators.py +107 -0
- sciel/engine/output_measurements.py +44 -0
- sciel/engine/output_novelty.py +256 -0
- sciel/engine/parallel.py +472 -0
- sciel/engine/parallel_calls.py +330 -0
- sciel/engine/parallel_control.py +51 -0
- sciel/engine/parallel_recovery.py +363 -0
- sciel/engine/parallel_schedule.py +215 -0
- sciel/engine/parallel_store.py +433 -0
- sciel/engine/population_view.py +113 -0
- sciel/engine/portfolio_allocation.py +74 -0
- sciel/engine/probe.py +75 -0
- sciel/engine/prompt/__init__.py +0 -0
- sciel/engine/prompt/budget.py +20 -0
- sciel/engine/prompt/build.py +202 -0
- sciel/engine/prompt/parse.py +54 -0
- sciel/engine/prompt/patch.py +101 -0
- sciel/engine/prompt/sources.py +10 -0
- sciel/engine/prompt/templates/cross.txt +26 -0
- sciel/engine/prompt/templates/diff.txt +24 -0
- sciel/engine/prompt/templates/error_repair.txt +23 -0
- sciel/engine/prompt/templates/fix.txt +8 -0
- sciel/engine/prompt/templates/full_rewrite.txt +24 -0
- sciel/engine/prompt/templates/idea.txt +27 -0
- sciel/engine/provider_abandonment.py +15 -0
- sciel/engine/recovery.py +85 -0
- sciel/engine/repeat_execution.py +177 -0
- sciel/engine/repeat_journal.py +91 -0
- sciel/engine/repeat_learning.py +20 -0
- sciel/engine/repeat_planning.py +128 -0
- sciel/engine/repeat_policy.py +131 -0
- sciel/engine/repeat_promotion.py +147 -0
- sciel/engine/repeat_state.py +253 -0
- sciel/engine/repeat_support.py +175 -0
- sciel/engine/research_artifacts.py +323 -0
- sciel/engine/research_candidate.py +84 -0
- sciel/engine/research_cells_context.py +168 -0
- sciel/engine/research_culture.py +119 -0
- sciel/engine/research_queue.py +129 -0
- sciel/engine/research_search_evidence.py +160 -0
- sciel/engine/research_targets.py +204 -0
- sciel/engine/research_tool_signals.py +57 -0
- sciel/engine/run_lock.py +37 -0
- sciel/engine/runtime.py +165 -0
- sciel/engine/schedule.py +179 -0
- sciel/engine/siblings.py +135 -0
- sciel/engine/source_identity.py +16 -0
- sciel/engine/step_cycle.py +217 -0
- sciel/engine/step_plan.py +405 -0
- sciel/engine/telemetry.py +168 -0
- sciel/engine/types.py +87 -0
- sciel/engine/validation.py +444 -0
- sciel/engine/viability.py +431 -0
- sciel/engine/warm_start.py +69 -0
- sciel/engine/worker.py +294 -0
- sciel/engine/worker_feedback.py +131 -0
- sciel/eval/__init__.py +0 -0
- sciel/eval/_candidate_worker.py +131 -0
- sciel/eval/_repeat_runner.py +229 -0
- sciel/eval/_runner.py +280 -0
- sciel/eval/_scorer_worker.py +24 -0
- sciel/eval/candidate_backend.py +209 -0
- sciel/eval/candidate_config.py +58 -0
- sciel/eval/candidate_evidence.py +52 -0
- sciel/eval/candidate_receipts.py +272 -0
- sciel/eval/candidate_registry.py +2 -0
- sciel/eval/cascade.py +55 -0
- sciel/eval/facade.py +153 -0
- sciel/eval/native_geometry.py +251 -0
- sciel/eval/near_output.py +147 -0
- sciel/eval/output_identity.py +308 -0
- sciel/eval/packing_geometry.py +185 -0
- sciel/eval/registry.py +251 -0
- sciel/eval/repeat_docker.py +187 -0
- sciel/eval/repeat_draw.py +466 -0
- sciel/eval/repeat_io.py +51 -0
- sciel/eval/sandbox.py +350 -0
- sciel/eval/scorer_container.py +186 -0
- sciel/eval/task_prompt.py +82 -0
- sciel/eval/trusted_scoring/__init__.py +1 -0
- sciel/eval/trusted_scoring/adapter.py +125 -0
- sciel/eval/trusted_scoring/beat.py +191 -0
- sciel/eval/trusted_scoring/circle.py +102 -0
- sciel/eval/trusted_scoring/heil.py +107 -0
- sciel/eval/trusted_scoring/transport.py +120 -0
- sciel/evidence/__init__.py +1 -0
- sciel/evidence/change_audit.py +243 -0
- sciel/evidence/eligibility.py +110 -0
- sciel/evidence/measurement.py +186 -0
- sciel/evidence/restart_optimizer_trace.py +189 -0
- sciel/evidence/restart_trace.py +54 -0
- sciel/evidence/restart_trace_recorder.py +253 -0
- sciel/evidence/restart_trace_source.py +31 -0
- sciel/evidence/restart_trace_validation.py +234 -0
- sciel/evidence/restart_trace_values.py +231 -0
- sciel/local_task.py +142 -0
- sciel/methods/__init__.py +11 -0
- sciel/methods/__main__.py +397 -0
- sciel/methods/_loader.py +99 -0
- sciel/methods/_runner.py +225 -0
- sciel/methods/budget.py +322 -0
- sciel/methods/campaign.py +372 -0
- sciel/methods/configuration.py +139 -0
- sciel/methods/coordinator.py +368 -0
- sciel/methods/coordinator_context.py +108 -0
- sciel/methods/coordinator_contracts.py +42 -0
- sciel/methods/coordinator_episode.py +251 -0
- sciel/methods/coordinator_exchange.py +156 -0
- sciel/methods/coordinator_execution.py +170 -0
- sciel/methods/coordinator_planning.py +156 -0
- sciel/methods/coordinator_policy.py +193 -0
- sciel/methods/engine_bridge.py +342 -0
- sciel/methods/evidence.py +384 -0
- sciel/methods/examples.py +255 -0
- sciel/methods/executor.py +519 -0
- sciel/methods/funding.py +119 -0
- sciel/methods/materialize.py +248 -0
- sciel/methods/models.py +242 -0
- sciel/methods/proposals.py +289 -0
- sciel/methods/provider_budget.py +71 -0
- sciel/methods/registry.py +500 -0
- sciel/methods/registry_records.py +117 -0
- sciel/methods/resource_values.py +129 -0
- sciel/methods/tasks.py +203 -0
- sciel/methods/technical.py +167 -0
- sciel/methods/transport.py +217 -0
- sciel/population.py +15 -0
- sciel/research_tools/__init__.py +2 -0
- sciel/research_tools/artifact_manifest.py +207 -0
- sciel/research_tools/artifact_reading.py +34 -0
- sciel/research_tools/canonical_diagnostics.py +241 -0
- sciel/research_tools/canonical_evidence.py +94 -0
- sciel/research_tools/cells.py +394 -0
- sciel/research_tools/comparison_assessment.py +89 -0
- sciel/research_tools/config.py +174 -0
- sciel/research_tools/continuations.py +289 -0
- sciel/research_tools/controller.py +236 -0
- sciel/research_tools/controller_jobs.py +315 -0
- sciel/research_tools/controller_state.py +204 -0
- sciel/research_tools/decision_projection.py +116 -0
- sciel/research_tools/episode_evidence.py +129 -0
- sciel/research_tools/episode_execution.py +249 -0
- sciel/research_tools/episode_results.py +224 -0
- sciel/research_tools/experiment_protocol.py +271 -0
- sciel/research_tools/followups.py +442 -0
- sciel/research_tools/job_worker.py +240 -0
- sciel/research_tools/jobs.py +364 -0
- sciel/research_tools/library.py +357 -0
- sciel/research_tools/lifecycle.py +377 -0
- sciel/research_tools/lifecycle_delivery.py +198 -0
- sciel/research_tools/lifecycle_evidence.py +324 -0
- sciel/research_tools/observation_cards.py +179 -0
- sciel/research_tools/planning.py +152 -0
- sciel/research_tools/projection_data.py +169 -0
- sciel/research_tools/projection_validation.py +133 -0
- sciel/research_tools/prompt_builder.py +393 -0
- sciel/research_tools/prompt_sections.py +377 -0
- sciel/research_tools/replay_feedback.py +153 -0
- sciel/research_tools/research_steps.py +222 -0
- sciel/research_tools/result_contract.py +73 -0
- sciel/research_tools/result_projection.py +319 -0
- sciel/research_tools/retained_observations.py +227 -0
- sciel/research_tools/sequential_research.py +371 -0
- sciel/research_tools/shared_evidence.py +408 -0
- sciel/research_tools/sharing.py +287 -0
- sciel/research_tools/stage_data.py +68 -0
- sciel/research_tools/tool_actions.py +241 -0
- sciel/research_tools/tool_artifacts.py +175 -0
- sciel/research_tools/tool_protocol.py +41 -0
- sciel/research_tools/transfer_jobs.py +190 -0
- sciel/reward.py +181 -0
- sciel/rl/__init__.py +3 -0
- sciel/rl/critic.py +104 -0
- sciel/rl/policy.py +235 -0
- sciel/rl/returns.py +56 -0
- sciel/rng.py +38 -0
- sciel/run_log.py +212 -0
- sciel/solvers/__init__.py +1 -0
- sciel/solvers/circle_anytime.py +257 -0
- sciel/solvers/circle_lp_initializer.py +132 -0
- sciel/solvers/circle_relocation.py +121 -0
- sciel/stats.py +217 -0
- sciel/swm/__init__.py +6 -0
- sciel/swm/archive.py +91 -0
- sciel/swm/diffusion.py +61 -0
- sciel/swm/embedding.py +94 -0
- sciel/swm/model.py +200 -0
- sciel/swm/niches.py +46 -0
- sciel/swm/sets.py +63 -0
- sciel/swm/tabular.py +66 -0
- sciel/swm/targets.py +63 -0
- sciel/swm/world.py +500 -0
- sciel/task.py +21 -0
- sciel/taskbuilder/__init__.py +118 -0
- sciel/taskbuilder/audit.py +92 -0
- sciel/taskbuilder/draft.py +69 -0
- sciel/taskbuilder/materials.py +88 -0
- sciel/theory/__init__.py +7 -0
- sciel/theory/assumptions.py +131 -0
- sciel/theory/claims.py +138 -0
- sciel/theory/experiments.py +106 -0
- sciel/theory/findings.py +148 -0
- sciel/theory/procedures.py +89 -0
- sciel/theory/schools.py +64 -0
- sciel/theory/strategies.py +85 -0
- sciel/theory/trials.py +107 -0
- sciel/tui/__init__.py +0 -0
- sciel/tui/board.py +52 -0
- sciel/ui/__init__.py +1 -0
- sciel/ui/activity.py +112 -0
- sciel/ui/engine.py +169 -0
- sciel/ui/render.py +165 -0
- sciel/ui/state.py +343 -0
- sciel/ui/static/engine.js +162 -0
- sciel/ui/static/index.html +397 -0
- sciel/ui/terminal.py +455 -0
- sciel/ui/views.py +307 -0
- sciel/ui/web.py +144 -0
- sciel-0.23.2.dist-info/METADATA +508 -0
- sciel-0.23.2.dist-info/RECORD +305 -0
- sciel-0.23.2.dist-info/WHEEL +5 -0
- sciel-0.23.2.dist-info/entry_points.txt +2 -0
- sciel-0.23.2.dist-info/top_level.txt +1 -0
sciel/cli/main.py
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"""Command-line interface for running and managing experiments."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import signal
|
|
9
|
+
import sys
|
|
10
|
+
import threading
|
|
11
|
+
import time
|
|
12
|
+
|
|
13
|
+
def build_engine(*args, **kwargs):
|
|
14
|
+
"""Load search dependencies only when building an engine."""
|
|
15
|
+
from ..engine.factory import build_engine as factory
|
|
16
|
+
return factory(*args, **kwargs)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _default_tasks_root() -> str:
|
|
20
|
+
here = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(
|
|
21
|
+
os.path.abspath(__file__)))))
|
|
22
|
+
return os.path.join(here, "tasks")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TaskRootError(ValueError):
|
|
26
|
+
"""An unavailable local task bundle, reported as a CLI usage error."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _tasks_root(args, *, task_name=None) -> str:
|
|
30
|
+
root = args.tasks_root if args.tasks_root is not None else _default_tasks_root()
|
|
31
|
+
guidance = ("Pass --tasks-root /path/to/tasks containing <suite>/<name>/task.yaml. "
|
|
32
|
+
"Task bundles are not included in the installed wheel.")
|
|
33
|
+
if not os.path.isdir(root):
|
|
34
|
+
raise TaskRootError(f"Task root is not a directory: {root!r}. {guidance}")
|
|
35
|
+
if task_name is not None and not os.path.isfile(os.path.join(root, task_name, "task.yaml")):
|
|
36
|
+
raise TaskRootError(f"Task {task_name!r} was not found in task root {root!r}. {guidance}")
|
|
37
|
+
return root
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _resolve_config(config_path: str, seed: int | None) -> dict:
|
|
41
|
+
from ..config import load_config, validate
|
|
42
|
+
cfg = validate(load_config(config_path))
|
|
43
|
+
if seed is not None:
|
|
44
|
+
cfg["random_seed"] = seed
|
|
45
|
+
return cfg
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _run_engine(engine):
|
|
49
|
+
if not hasattr(engine, 'request_stop') or threading.current_thread() is not threading.main_thread():
|
|
50
|
+
return engine.run()
|
|
51
|
+
previous = {sig: signal.getsignal(sig) for sig in (signal.SIGINT, signal.SIGTERM)}
|
|
52
|
+
def stop(signum, frame):
|
|
53
|
+
engine.request_stop()
|
|
54
|
+
try:
|
|
55
|
+
for sig in previous:
|
|
56
|
+
signal.signal(sig, stop)
|
|
57
|
+
return engine.run()
|
|
58
|
+
finally:
|
|
59
|
+
for sig, handler in previous.items():
|
|
60
|
+
signal.signal(sig, handler)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def cmd_run(args) -> int:
|
|
64
|
+
from pathlib import Path
|
|
65
|
+
from .live import default_mode, follow, spawn, write_config
|
|
66
|
+
from .start import StartError, next_run_dir, resolve
|
|
67
|
+
from .supervise import SuperviseError, ensure_credentials, supervise
|
|
68
|
+
target = Path(args.config)
|
|
69
|
+
default_root = args.tasks_root or _default_tasks_root()
|
|
70
|
+
try:
|
|
71
|
+
if target.suffix == ".py" or (not target.exists() and (Path(default_root) / args.config / "task.yaml").is_file()):
|
|
72
|
+
cfg, tasks_root, stem = resolve(args.config, tasks_root=default_root, budget=args.budget, seed=args.seed)
|
|
73
|
+
else:
|
|
74
|
+
cfg, tasks_root = _resolve_config(args.config, args.seed), default_root
|
|
75
|
+
if args.budget is not None:
|
|
76
|
+
cfg["budget"] = args.budget
|
|
77
|
+
stem = cfg["task"].replace("/", "_")
|
|
78
|
+
except (StartError, SuperviseError) as exc:
|
|
79
|
+
print(str(exc), file=sys.stderr)
|
|
80
|
+
return 2
|
|
81
|
+
if args.run_id:
|
|
82
|
+
run_dir = Path(args.outputs, args.run_id).resolve()
|
|
83
|
+
elif args.outputs != ".sciel/runs":
|
|
84
|
+
run_dir = Path(args.outputs, f"{stem}_{int(time.time())}_s{cfg['random_seed']}").resolve()
|
|
85
|
+
else:
|
|
86
|
+
run_dir = next_run_dir(stem)
|
|
87
|
+
if run_dir.exists() and any(run_dir.iterdir()):
|
|
88
|
+
raise ValueError('Run directory is not empty; use resume or a new --run-id')
|
|
89
|
+
if getattr(args, 'warm_start_from', None):
|
|
90
|
+
from ..engine.warm_start import from_run
|
|
91
|
+
cfg['warm_start'] = from_run(args.warm_start_from, cfg['task'])
|
|
92
|
+
mode = args.watch or default_mode()
|
|
93
|
+
override = args.tasks_root is not None or cfg["task"].startswith("local/")
|
|
94
|
+
if mode == "none":
|
|
95
|
+
summary = supervise(run_dir, cfg, tasks_root=tasks_root, fresh=True, tasks_root_override=override,
|
|
96
|
+
log=lambda m: print(m, file=sys.stderr, flush=True))
|
|
97
|
+
print(json.dumps(summary))
|
|
98
|
+
return 0
|
|
99
|
+
try:
|
|
100
|
+
ensure_credentials(cfg)
|
|
101
|
+
except (OSError, EOFError) as exc:
|
|
102
|
+
print(f"no model key: {exc}", file=sys.stderr)
|
|
103
|
+
return 2
|
|
104
|
+
child = spawn(run_dir, fresh_config=write_config(cfg, run_dir), tasks_root=tasks_root if override else None)
|
|
105
|
+
return follow(run_dir, child, mode)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def cmd_task(args) -> int:
|
|
109
|
+
from ..taskbuilder import interactive
|
|
110
|
+
from .start import StartError, workdir
|
|
111
|
+
try:
|
|
112
|
+
return interactive(args.folder, tasks_root=str(workdir() / "tasks"), note=args.note)
|
|
113
|
+
except (StartError, ValueError) as exc:
|
|
114
|
+
print(str(exc), file=sys.stderr)
|
|
115
|
+
return 2
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def cmd_watch(args) -> int:
|
|
119
|
+
from pathlib import Path
|
|
120
|
+
from .live import follow
|
|
121
|
+
run_dir = Path(args.run_dir).resolve()
|
|
122
|
+
if not (run_dir / "sciel_events.jsonl").exists():
|
|
123
|
+
print(f"No run at {run_dir}", file=sys.stderr)
|
|
124
|
+
return 2
|
|
125
|
+
return follow(run_dir, None, "web" if args.cmd == "web" else ("both" if args.web else "terminal"))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def cmd_resume(args) -> int:
|
|
129
|
+
"""Resume from the checkpoint's own config.
|
|
130
|
+
|
|
131
|
+
The run directory's config.yaml used to be loaded and validated first and then
|
|
132
|
+
overwritten by the checkpoint's copy on the next line: the value was never used,
|
|
133
|
+
yet a validation error in that unused file aborted the resume -- which defeats
|
|
134
|
+
DEPRECATED_KEYS, the mechanism that exists to keep old snapshots resumable."""
|
|
135
|
+
from pathlib import Path
|
|
136
|
+
from ..engine import checkpoint
|
|
137
|
+
from .live import default_mode, follow, spawn
|
|
138
|
+
from .supervise import SuperviseError, ensure_credentials, start_config, supervise
|
|
139
|
+
run_dir = Path(args.run_dir).resolve()
|
|
140
|
+
try:
|
|
141
|
+
cfg = start_config(run_dir, None)
|
|
142
|
+
ensure_credentials(cfg)
|
|
143
|
+
except SuperviseError as exc:
|
|
144
|
+
print(str(exc), file=sys.stderr)
|
|
145
|
+
return 2
|
|
146
|
+
mode = args.watch or default_mode()
|
|
147
|
+
from .start import _tasks_root_of
|
|
148
|
+
tasks_root = args.tasks_root or _tasks_root_of(run_dir, _default_tasks_root())
|
|
149
|
+
override = args.tasks_root is not None or cfg["task"].startswith("local/")
|
|
150
|
+
if mode != "none" and not args.force_identity:
|
|
151
|
+
child = spawn(run_dir, tasks_root=tasks_root if override else None, recover=args.abandon_provider_failure)
|
|
152
|
+
return follow(run_dir, child, mode)
|
|
153
|
+
if args.force_identity:
|
|
154
|
+
engine = build_engine(cfg, tasks_root, str(run_dir), python=sys.executable,
|
|
155
|
+
tasks_root_override=args.tasks_root is not None)
|
|
156
|
+
try:
|
|
157
|
+
checkpoint.load(engine, str(run_dir / "checkpoint.json"), allow_identity_mismatch=True)
|
|
158
|
+
summary = _run_engine(engine)
|
|
159
|
+
finally:
|
|
160
|
+
engine.close()
|
|
161
|
+
else:
|
|
162
|
+
try:
|
|
163
|
+
summary = supervise(run_dir, cfg, tasks_root=tasks_root, fresh=False, tasks_root_override=override,
|
|
164
|
+
recover=args.abandon_provider_failure,
|
|
165
|
+
log=lambda m: print(m, file=sys.stderr, flush=True))
|
|
166
|
+
except checkpoint.IdentityMismatch as e:
|
|
167
|
+
print(str(e), file=sys.stderr)
|
|
168
|
+
return 2
|
|
169
|
+
except SuperviseError as exc:
|
|
170
|
+
print(str(exc), file=sys.stderr)
|
|
171
|
+
return 2
|
|
172
|
+
print(json.dumps(summary))
|
|
173
|
+
return 0
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def cmd_tasks(args) -> int:
|
|
177
|
+
from ..eval.registry import determinism_check, discover, load_task
|
|
178
|
+
if args.action == "hash" and not args.name:
|
|
179
|
+
print("usage: sciel tasks hash <suite>/<name>", file=sys.stderr)
|
|
180
|
+
return 2
|
|
181
|
+
tasks_root = _tasks_root(args, task_name=args.name if args.action == "hash" else None)
|
|
182
|
+
if args.action in ("list", "validate"):
|
|
183
|
+
tasks = discover(tasks_root)
|
|
184
|
+
if not tasks:
|
|
185
|
+
raise TaskRootError(
|
|
186
|
+
f"No tasks found in task root {tasks_root!r}. "
|
|
187
|
+
"Pass --tasks-root /path/to/tasks containing <suite>/<name>/task.yaml. "
|
|
188
|
+
"Task bundles are not included in the installed wheel.")
|
|
189
|
+
if args.action == "list":
|
|
190
|
+
for t in tasks:
|
|
191
|
+
print(f"{t.qualified_name}\t{t.task_hash[:12]}\t{t.origin}")
|
|
192
|
+
return 0
|
|
193
|
+
if args.action == "validate":
|
|
194
|
+
ok = True
|
|
195
|
+
for t in tasks:
|
|
196
|
+
dc = determinism_check(t, python=sys.executable,
|
|
197
|
+
program_path=args.probe)
|
|
198
|
+
status = "OK" if dc["valid"] else "FAIL"
|
|
199
|
+
ok = ok and dc["valid"]
|
|
200
|
+
print(f"{status}\t{t.qualified_name}\t{dc}")
|
|
201
|
+
if not dc["informative"]:
|
|
202
|
+
print(f" note: both runs of {dc['probe']} scored 0.0, so this "
|
|
203
|
+
f"proves nothing about whether the task is deterministic. "
|
|
204
|
+
f"Re-check with --probe <a real evolved program>.")
|
|
205
|
+
return 0 if ok else 1
|
|
206
|
+
if args.action == "hash":
|
|
207
|
+
t = load_task(os.path.join(tasks_root, args.name))
|
|
208
|
+
print(t.task_hash)
|
|
209
|
+
return 0
|
|
210
|
+
return 2
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def cmd_stop(args) -> int:
|
|
216
|
+
"""Ask the run to stop, then wait until it has saved and stopped, showing what it still finishes."""
|
|
217
|
+
from pathlib import Path
|
|
218
|
+
from ..engine.runtime import process_matches
|
|
219
|
+
run_dir = Path(args.run_dir)
|
|
220
|
+
try:
|
|
221
|
+
runtime = json.loads((run_dir / 'runtime.json').read_text())
|
|
222
|
+
except (OSError, ValueError):
|
|
223
|
+
print(f'No run at {run_dir}.', file=sys.stderr)
|
|
224
|
+
return 2
|
|
225
|
+
if runtime.get('status') != 'running':
|
|
226
|
+
print(f'Nothing to stop: the run is {runtime.get("status")}.', file=sys.stderr)
|
|
227
|
+
return 2
|
|
228
|
+
if process_matches(runtime) is not True:
|
|
229
|
+
print('The run says it is running, but its engine process is gone (it was killed or crashed). '
|
|
230
|
+
f'Resume it with: sciel resume {run_dir}', file=sys.stderr)
|
|
231
|
+
return 2
|
|
232
|
+
(run_dir / 'STOP').touch()
|
|
233
|
+
print('Stopping: work already sent to the model or the evaluator finishes first, then the run saves and stops.')
|
|
234
|
+
if getattr(args, 'no_wait', True):
|
|
235
|
+
return 0
|
|
236
|
+
from ..ui.activity import Activity
|
|
237
|
+
activity, started = Activity(run_dir), time.monotonic()
|
|
238
|
+
while True:
|
|
239
|
+
try:
|
|
240
|
+
runtime = json.loads((run_dir / 'runtime.json').read_text())
|
|
241
|
+
except (OSError, ValueError):
|
|
242
|
+
runtime = {}
|
|
243
|
+
if runtime.get('status') not in ('running', None) or process_matches(runtime) is False:
|
|
244
|
+
print(f'Stopped ({runtime.get("status")}) after {time.monotonic() - started:.0f} s. '
|
|
245
|
+
f'Continue it with: sciel resume {run_dir}')
|
|
246
|
+
return 0
|
|
247
|
+
busy = [j for j in activity.read()['jobs'] if j['doing'] not in ('done', 'queued')]
|
|
248
|
+
line = ', '.join(f"I{j['island']} {j['doing']}" for j in busy) or 'saving'
|
|
249
|
+
print(f'\r {time.monotonic() - started:4.0f} s waiting for: {line[:90]:<90}', end='', flush=True)
|
|
250
|
+
time.sleep(1)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def main(argv=None) -> int:
|
|
254
|
+
p = argparse.ArgumentParser(prog="sciel")
|
|
255
|
+
sub = p.add_subparsers(dest="cmd", required=True, metavar="command")
|
|
256
|
+
|
|
257
|
+
watch_help = "where to follow the run: both (default in a terminal), terminal, web, or none"
|
|
258
|
+
pr = sub.add_parser("run", help="Start a run: a config file, a .py file with solve() and score(), or a task")
|
|
259
|
+
pr.add_argument("config", metavar="target")
|
|
260
|
+
pr.add_argument("--seed", type=int, default=None)
|
|
261
|
+
pr.add_argument("--budget", type=int, default=None, help="number of evaluations")
|
|
262
|
+
pr.add_argument("--watch", choices=("both", "terminal", "web", "none"), default=None, help=watch_help)
|
|
263
|
+
pr.add_argument("--outputs", default=".sciel/runs", help="where run directories go")
|
|
264
|
+
pr.add_argument("--run-id", default=None)
|
|
265
|
+
pr.add_argument("--tasks-root", default=None)
|
|
266
|
+
pr.add_argument('--warm-start-from', metavar='RUN_DIR',
|
|
267
|
+
help='start a new run from a checkpoint best source, freshly evaluated')
|
|
268
|
+
pr.set_defaults(func=cmd_run)
|
|
269
|
+
|
|
270
|
+
prs = sub.add_parser("resume", help="Continue a paused or stopped run")
|
|
271
|
+
prs.add_argument("--force-identity", action="store_true",
|
|
272
|
+
help="resume even though the task or the diversity axis changed "
|
|
273
|
+
"since the checkpoint was written (the archive and the new "
|
|
274
|
+
"children will not be comparable)")
|
|
275
|
+
prs.add_argument("--abandon-provider-failure", action="store_true",
|
|
276
|
+
help="give up the provider request the run stopped on and continue")
|
|
277
|
+
prs.add_argument("--watch", choices=("both", "terminal", "web", "none"), default=None, help=watch_help)
|
|
278
|
+
prs.add_argument("run_dir")
|
|
279
|
+
prs.add_argument("--tasks-root", default=None)
|
|
280
|
+
prs.set_defaults(func=cmd_resume)
|
|
281
|
+
|
|
282
|
+
pt2 = sub.add_parser("task", help="Turn a folder of materials into a checked task, then search it")
|
|
283
|
+
pt2.add_argument("folder")
|
|
284
|
+
pt2.add_argument("--note", default="", help="what you want from the task, in a sentence")
|
|
285
|
+
pt2.set_defaults(func=cmd_task)
|
|
286
|
+
|
|
287
|
+
pw = sub.add_parser("watch", help="Follow a run in the terminal")
|
|
288
|
+
pw.add_argument("run_dir")
|
|
289
|
+
pw.add_argument("--web", action="store_true", help="also open the web page")
|
|
290
|
+
pw.set_defaults(func=cmd_watch)
|
|
291
|
+
|
|
292
|
+
pweb = sub.add_parser("web", help="Open a run's live page in the browser")
|
|
293
|
+
pweb.add_argument("run_dir")
|
|
294
|
+
pweb.set_defaults(func=cmd_watch)
|
|
295
|
+
|
|
296
|
+
pt = sub.add_parser("tasks")
|
|
297
|
+
pt.add_argument("action", choices=["list", "validate", "hash"])
|
|
298
|
+
pt.add_argument("name", nargs="?", default=None)
|
|
299
|
+
pt.add_argument("--probe", default=None,
|
|
300
|
+
help="program to run twice for the determinism check; the default "
|
|
301
|
+
"is the task's seed, which for a constant seed proves nothing")
|
|
302
|
+
pt.add_argument("--tasks-root", default=None)
|
|
303
|
+
pt.set_defaults(func=cmd_tasks)
|
|
304
|
+
|
|
305
|
+
ps = sub.add_parser("stop", help="Stop a run safely: work already sent finishes, then it saves and stops")
|
|
306
|
+
ps.add_argument("run_dir")
|
|
307
|
+
ps.add_argument("--no-wait", action="store_true", help="return right after asking the run to stop")
|
|
308
|
+
ps.set_defaults(func=cmd_stop)
|
|
309
|
+
|
|
310
|
+
# The guard has to run BEFORE parse_args: argparse rejects an unknown option
|
|
311
|
+
# first, so the explanatory message was unreachable. It also read sys.argv rather
|
|
312
|
+
# than the argv it was given, so it was wrong under programmatic calls.
|
|
313
|
+
source = list(argv) if argv is not None else sys.argv[1:]
|
|
314
|
+
from .profile import load_keys
|
|
315
|
+
load_keys()
|
|
316
|
+
if not source:
|
|
317
|
+
from .start import menu
|
|
318
|
+
return menu(_default_tasks_root())
|
|
319
|
+
if source[0].endswith(".py") and os.path.isfile(source[0]):
|
|
320
|
+
source = ["run"] + source
|
|
321
|
+
argv = source
|
|
322
|
+
if source[:1] == ["_engine"]:
|
|
323
|
+
from .supervise import main as supervise_main
|
|
324
|
+
return supervise_main(source[1:])
|
|
325
|
+
if source[:1] == ["run"] and "-s" in source:
|
|
326
|
+
raise SystemExit("seed via --seed / overlay {random_seed: N}, not -s")
|
|
327
|
+
args = p.parse_args(argv)
|
|
328
|
+
try:
|
|
329
|
+
return args.func(args)
|
|
330
|
+
except TaskRootError as exc:
|
|
331
|
+
p.error(str(exc))
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
if __name__ == "__main__":
|
|
335
|
+
raise SystemExit(main())
|
sciel/cli/profile.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""The default profile: a working configuration from nothing but a task and an API key in the environment."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
KEYS_FILE = Path.home() / ".config" / "sciel" / "keys"
|
|
9
|
+
|
|
10
|
+
PROVIDERS = (
|
|
11
|
+
("ANTHROPIC_API_KEY", "Anthropic", "claude-sonnet-5-5",
|
|
12
|
+
{"provider": "anthropic", "models": ["claude-sonnet-5-5"], "api_key_env": "ANTHROPIC_API_KEY",
|
|
13
|
+
"reasoning_effort": "medium", "max_tokens": 32000, "timeout": 600}),
|
|
14
|
+
("OPENROUTER_API_KEY", "OpenRouter", "anthropic/claude-sonnet-5.5",
|
|
15
|
+
{"models": ["anthropic/claude-sonnet-5.5"], "weights": [1.0], "api_base": "https://openrouter.ai/api/v1",
|
|
16
|
+
"api_key_env": "OPENROUTER_API_KEY", "reasoning_effort": "medium", "max_tokens": 32000, "timeout": 600,
|
|
17
|
+
"model_capabilities": {"anthropic/claude-sonnet-5.5": {"temperature": False}}, "max_retries": 1}),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
BASE = {"num_islands": 3, "pop_cap": 50, "archive_size": 20, "grid_bins": 10, "inflight_cap": 4, "dup_cap": 4,
|
|
21
|
+
"backstop_k": 10, "schedule_policy": "sh", "milestone_fracs": [0.5, 0.75], "op_temperature": 0.5,
|
|
22
|
+
"op_floor": 0.05, "op_window": 20, "selection_floor": 0.001, "tau_floor": 0.001, "reward_w_pop": 1.0,
|
|
23
|
+
"reward_w_isl": 1.0, "base_temp": 0.7, "confirm_records": False, "checkpoint_on_milestone": True,
|
|
24
|
+
"embed_grid": False, "candidate_novelty": {"enabled": True},
|
|
25
|
+
"swm": {"embedding_api_base": None, "embedding_model": "hashed-tokens"},
|
|
26
|
+
"parallel_search": {"enabled": True, "workers": 6,
|
|
27
|
+
"host_evaluator_slots": max(2, (os.cpu_count() or 4) - 2)}}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def load_keys():
|
|
31
|
+
"""Fill missing provider keys from the user's saved keys file."""
|
|
32
|
+
try:
|
|
33
|
+
lines = KEYS_FILE.read_text().splitlines()
|
|
34
|
+
except OSError:
|
|
35
|
+
return
|
|
36
|
+
for line in lines:
|
|
37
|
+
name, sep, value = line.partition("=")
|
|
38
|
+
if sep and name.strip() and value.strip():
|
|
39
|
+
os.environ.setdefault(name.strip(), value.strip())
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def save_key(name: str, value: str):
|
|
43
|
+
KEYS_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
44
|
+
kept = [line for line in (KEYS_FILE.read_text().splitlines() if KEYS_FILE.exists() else [])
|
|
45
|
+
if not line.startswith(name + "=")]
|
|
46
|
+
fd = os.open(KEYS_FILE, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
|
47
|
+
with os.fdopen(fd, "w") as stream:
|
|
48
|
+
stream.write("\n".join(kept + [f"{name}={value}"]) + "\n")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def detect():
|
|
52
|
+
"""The first provider whose key is available, as (env name, label, model, llm config), or None."""
|
|
53
|
+
load_keys()
|
|
54
|
+
for env, label, model, llm in PROVIDERS:
|
|
55
|
+
if os.environ.get(env):
|
|
56
|
+
return env, label, model, dict(llm)
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def default_config(task: str, llm: dict, *, budget: int = 40, seed: int = 0) -> dict:
|
|
61
|
+
"""Host capacity limits are fixed per capacity root, so this profile keeps its own root in ./.sciel."""
|
|
62
|
+
from ..config import validate
|
|
63
|
+
parallel = {**BASE["parallel_search"], "capacity_dir": str(Path.cwd() / ".sciel" / "capacity")}
|
|
64
|
+
return validate({**BASE, "parallel_search": parallel, "task": task, "budget": budget, "random_seed": seed,
|
|
65
|
+
"llm": llm})
|
sciel/cli/start.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Starting without a config: pick a provider from the environment, turn the target into a task, ask the rest."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import getpass
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from rich.console import Console
|
|
12
|
+
|
|
13
|
+
ACCENT, MUTED, OK = "#64D2FF", "#8A8A8E", "#3DAE7C"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class StartError(ValueError):
|
|
17
|
+
"""The target cannot be started; the message says why."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def workdir() -> Path:
|
|
21
|
+
return Path.cwd() / ".sciel"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def next_run_dir(stem: str) -> Path:
|
|
25
|
+
runs = workdir() / "runs"
|
|
26
|
+
n = 1
|
|
27
|
+
while (runs / f"{stem}-{n}").exists():
|
|
28
|
+
n += 1
|
|
29
|
+
return runs / f"{stem}-{n}"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def clean_key(key: str) -> str:
|
|
33
|
+
"""Strip whitespace and undo a key pasted twice into a prompt that shows nothing."""
|
|
34
|
+
key = "".join(key.split())
|
|
35
|
+
half = len(key) // 2
|
|
36
|
+
return key[:half] if len(key) % 2 == 0 and half >= 20 and key[:half] == key[half:] else key
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def check_key(env: str, key: str) -> str | None:
|
|
40
|
+
"""None if the provider accepts the key, else what is wrong with it."""
|
|
41
|
+
if env == "OPENROUTER_API_KEY":
|
|
42
|
+
import urllib.error
|
|
43
|
+
import urllib.request
|
|
44
|
+
request = urllib.request.Request("https://openrouter.ai/api/v1/key", headers={"Authorization": f"Bearer {key}"})
|
|
45
|
+
try:
|
|
46
|
+
urllib.request.urlopen(request, timeout=20).close()
|
|
47
|
+
except urllib.error.HTTPError as exc:
|
|
48
|
+
return f"OpenRouter rejected this key (HTTP {exc.code})"
|
|
49
|
+
except OSError as exc:
|
|
50
|
+
return f"could not reach OpenRouter to check the key: {exc}"
|
|
51
|
+
return None
|
|
52
|
+
if env == "ANTHROPIC_API_KEY":
|
|
53
|
+
import anthropic
|
|
54
|
+
try:
|
|
55
|
+
anthropic.Anthropic(api_key=key, max_retries=0, timeout=20).models.list(limit=1)
|
|
56
|
+
except anthropic.AuthenticationError:
|
|
57
|
+
return "Anthropic rejected this key (HTTP 401)"
|
|
58
|
+
except anthropic.APIError as exc:
|
|
59
|
+
return f"could not check the key with Anthropic: {exc}"
|
|
60
|
+
return None
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def ask_provider(console: Console):
|
|
65
|
+
"""Use a key from the environment or the saved keys file; otherwise ask for one once."""
|
|
66
|
+
from .profile import PROVIDERS, detect, save_key
|
|
67
|
+
found = detect()
|
|
68
|
+
if found is not None:
|
|
69
|
+
return found
|
|
70
|
+
if not sys.stdin.isatty():
|
|
71
|
+
raise StartError("set ANTHROPIC_API_KEY or OPENROUTER_API_KEY")
|
|
72
|
+
console.print(f"[{MUTED}]No model key found. Which provider?[/]")
|
|
73
|
+
for i, (env, label, model, _) in enumerate(PROVIDERS, 1):
|
|
74
|
+
console.print(f" [{ACCENT}]{i}[/] {label} [{MUTED}]({model}, key in {env})[/]")
|
|
75
|
+
choice = console.input(f"[{ACCENT}]›[/] ").strip() or "1"
|
|
76
|
+
if choice not in {str(i) for i in range(1, len(PROVIDERS) + 1)}:
|
|
77
|
+
raise StartError("no provider chosen")
|
|
78
|
+
env, label, model, llm = PROVIDERS[int(choice) - 1]
|
|
79
|
+
for _ in range(3):
|
|
80
|
+
key = clean_key(getpass.getpass(f"{env} (hidden, paste once and press enter): "))
|
|
81
|
+
if not key:
|
|
82
|
+
raise StartError("no key given")
|
|
83
|
+
problem = check_key(env, key)
|
|
84
|
+
if problem is None:
|
|
85
|
+
console.print(f"[{OK}]✓[/] [{MUTED}]the key works[/]")
|
|
86
|
+
break
|
|
87
|
+
console.print(f"[#E5484D]{problem}[/]")
|
|
88
|
+
else:
|
|
89
|
+
raise StartError("no working key")
|
|
90
|
+
os.environ[env] = key
|
|
91
|
+
if console.input(f"[{MUTED}]save it in ~/.config/sciel/keys for next time? [Y/n][/] ").strip().lower() != "n":
|
|
92
|
+
save_key(env, key)
|
|
93
|
+
return env, label, model, dict(llm)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def resolve(target: str, *, tasks_root: str, budget=None, seed=None, console=None):
|
|
97
|
+
"""(config, tasks root, run name) for a config file, a single-file program, or a task name."""
|
|
98
|
+
from ..config import load_config, validate
|
|
99
|
+
from .profile import default_config
|
|
100
|
+
path = Path(target)
|
|
101
|
+
if path.suffix in (".yaml", ".yml", ".json") and path.is_file():
|
|
102
|
+
cfg = validate(load_config(str(path)))
|
|
103
|
+
if seed is not None:
|
|
104
|
+
cfg["random_seed"] = seed
|
|
105
|
+
if budget is not None:
|
|
106
|
+
cfg["budget"] = budget
|
|
107
|
+
return cfg, tasks_root, cfg["task"].replace("/", "_")
|
|
108
|
+
console = console or Console()
|
|
109
|
+
_, _, _, llm = ask_provider(console)
|
|
110
|
+
options = {"budget": budget or 40, "seed": seed or 0}
|
|
111
|
+
if path.suffix == ".py" and path.is_file():
|
|
112
|
+
from ..local_task import build
|
|
113
|
+
root = workdir() / "tasks"
|
|
114
|
+
return default_config(build(path, root), llm, **options), str(root), path.stem
|
|
115
|
+
if (Path(tasks_root) / target / "task.yaml").is_file():
|
|
116
|
+
return default_config(target, llm, **options), tasks_root, target.replace("/", "_")
|
|
117
|
+
raise StartError(f"{target} is not a config file, a .py file with solve() and score(), "
|
|
118
|
+
f"or a task under {tasks_root}")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _runs():
|
|
122
|
+
"""Unfinished runs that can continue, newest first, as (directory, status, engine alive)."""
|
|
123
|
+
from ..engine.runtime import process_matches
|
|
124
|
+
rows = []
|
|
125
|
+
for run in sorted((workdir() / "runs").glob("*/runtime.json"), key=lambda p: p.stat().st_mtime, reverse=True):
|
|
126
|
+
try:
|
|
127
|
+
runtime = json.loads(run.read_text())
|
|
128
|
+
except (OSError, ValueError):
|
|
129
|
+
continue
|
|
130
|
+
alive = runtime.get("status") == "running" and process_matches(runtime) is True
|
|
131
|
+
status = "running" if alive else ("lost" if runtime.get("status") == "running" else runtime.get("status"))
|
|
132
|
+
if status != "completed" and (run.parent / "checkpoint.json").exists():
|
|
133
|
+
rows.append((run.parent, status, alive))
|
|
134
|
+
return rows
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def menu(tasks_root: str) -> int:
|
|
138
|
+
"""The interactive start screen shown by a bare `sciel`."""
|
|
139
|
+
from .. import __version__
|
|
140
|
+
from ..demo import CIRCLES
|
|
141
|
+
from .live import follow, spawn, write_config
|
|
142
|
+
console = Console()
|
|
143
|
+
console.print(f"[bold {ACCENT}]SCIEL[/] [{MUTED}]search that gets better at searching · {__version__}[/]\n")
|
|
144
|
+
try:
|
|
145
|
+
env, label, model, _ = ask_provider(console)
|
|
146
|
+
except StartError as exc:
|
|
147
|
+
console.print(str(exc))
|
|
148
|
+
return 2
|
|
149
|
+
console.print(f"[{OK}]✓[/] [{MUTED}]model[/] {env} → {model} via {label}")
|
|
150
|
+
console.print(f"[{OK}]✓[/] [{MUTED}]profile[/] default · 3 islands · 40 evaluations")
|
|
151
|
+
console.print(f"[{MUTED}]·[/] [{MUTED}]saves to[/] ./.sciel run sciel here again to come back\n")
|
|
152
|
+
runs = _runs()
|
|
153
|
+
choices = [("1", "demo: 26 circles in a square", "a few minutes"),
|
|
154
|
+
("2", "a program of mine", "a .py file with solve() and score()")]
|
|
155
|
+
if runs:
|
|
156
|
+
choices.append(("3", f"continue {runs[0][0].name}", runs[0][1]))
|
|
157
|
+
console.print(f"[{MUTED}]WHAT SHOULD IT IMPROVE?[/]")
|
|
158
|
+
for key, title, hint in choices:
|
|
159
|
+
console.print(f" [{ACCENT}]{key}[/] {title:<36} [{MUTED}]{hint}[/]")
|
|
160
|
+
pick = console.input(f"[{ACCENT}]›[/] ").strip() or "1"
|
|
161
|
+
console.print(f"\n[{MUTED}]WATCH IN[/] [{ACCENT}]t[/] terminal [{ACCENT}]w[/] browser [{ACCENT}]b[/] both [{MUTED}](default)[/]")
|
|
162
|
+
mode = {"t": "terminal", "w": "web"}.get(console.input(f"[{ACCENT}]›[/] ").strip().lower(), "both")
|
|
163
|
+
if pick == "3" and runs:
|
|
164
|
+
run_dir, status, alive = runs[0]
|
|
165
|
+
child = None if alive else spawn(run_dir, tasks_root=_tasks_root_of(run_dir, tasks_root))
|
|
166
|
+
return follow(run_dir, child, mode)
|
|
167
|
+
if pick == "2":
|
|
168
|
+
target = console.input(f"[{MUTED}]path to the .py file:[/] ").strip()
|
|
169
|
+
elif pick == "1":
|
|
170
|
+
target = str(CIRCLES)
|
|
171
|
+
else:
|
|
172
|
+
console.print("no such choice")
|
|
173
|
+
return 2
|
|
174
|
+
try:
|
|
175
|
+
cfg, root, stem = resolve(target, tasks_root=tasks_root, console=console)
|
|
176
|
+
except (StartError, OSError, ValueError) as exc:
|
|
177
|
+
console.print(str(exc))
|
|
178
|
+
return 2
|
|
179
|
+
run_dir = next_run_dir(stem)
|
|
180
|
+
return follow(run_dir, spawn(run_dir, fresh_config=write_config(cfg, run_dir), tasks_root=root), mode)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _tasks_root_of(run_dir: Path, default: str) -> str:
|
|
184
|
+
"""Local tasks live under .sciel/tasks; everything else under the configured task root."""
|
|
185
|
+
try:
|
|
186
|
+
task = json.loads((run_dir / "checkpoint.json").read_text())["config"]["task"]
|
|
187
|
+
except (OSError, ValueError, KeyError):
|
|
188
|
+
return default
|
|
189
|
+
return str(workdir() / "tasks") if task.startswith("local/") else default
|