optpilot 0.1.0__tar.gz → 0.2.0__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.
- {optpilot-0.1.0 → optpilot-0.2.0}/LICENSE +0 -0
- optpilot-0.2.0/MANIFEST.in +29 -0
- optpilot-0.2.0/PKG-INFO +59 -0
- optpilot-0.2.0/README.md +28 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/pyproject.toml +16 -12
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/__init__.py +1 -1
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/__main__.py +0 -0
- optpilot-0.2.0/src/optpilot/_experiment_catalog.py +271 -0
- optpilot-0.2.0/src/optpilot/_experiment_draft.py +212 -0
- optpilot-0.2.0/src/optpilot/_experiment_execution.py +348 -0
- optpilot-0.2.0/src/optpilot/_experiment_interface.py +385 -0
- optpilot-0.2.0/src/optpilot/_experiment_store.py +237 -0
- optpilot-0.2.0/src/optpilot/_experiment_study.py +158 -0
- optpilot-0.2.0/src/optpilot/_experiment_worker.py +112 -0
- optpilot-0.2.0/src/optpilot/_harbor_auth.py +58 -0
- optpilot-0.2.0/src/optpilot/_harbor_results.py +149 -0
- optpilot-0.2.0/src/optpilot/_harbor_supervisor.py +87 -0
- optpilot-0.2.0/src/optpilot/_retired_cli.py +1260 -0
- optpilot-0.2.0/src/optpilot/_ssh_trial_worker.py +146 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/adapters.py +0 -0
- optpilot-0.2.0/src/optpilot/attempt_semantics.py +164 -0
- optpilot-0.2.0/src/optpilot/attempts.py +1155 -0
- optpilot-0.2.0/src/optpilot/authoring/contract.json +10 -0
- optpilot-0.2.0/src/optpilot/authoring/optpilot-evaluation/SKILL.md +79 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/candidate_materialization.py +55 -11
- optpilot-0.1.0/src/optpilot/candidate_files.py → optpilot-0.2.0/src/optpilot/candidate_staging.py +115 -83
- optpilot-0.2.0/src/optpilot/cli.py +41 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/config.py +848 -104
- optpilot-0.2.0/src/optpilot/config_errors.py +57 -0
- optpilot-0.2.0/src/optpilot/container_engine.py +251 -0
- optpilot-0.2.0/src/optpilot/container_launch.py +175 -0
- optpilot-0.2.0/src/optpilot/container_method_process.py +243 -0
- optpilot-0.2.0/src/optpilot/container_utils.py +16 -0
- optpilot-0.2.0/src/optpilot/dependency_closure.py +675 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/environment.py +0 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/evidence.py +20 -2
- optpilot-0.2.0/src/optpilot/example_packages.py +171 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/execution.py +19 -354
- optpilot-0.2.0/src/optpilot/experiment.py +438 -0
- optpilot-0.2.0/src/optpilot/experiment_cli.py +122 -0
- optpilot-0.2.0/src/optpilot/experiment_manual.py +127 -0
- optpilot-0.2.0/src/optpilot/experiment_resource_plan.py +514 -0
- optpilot-0.2.0/src/optpilot/experiment_resources.py +756 -0
- optpilot-0.2.0/src/optpilot/experiment_ssh.py +186 -0
- optpilot-0.2.0/src/optpilot/external_results.py +253 -0
- optpilot-0.2.0/src/optpilot/fixed_candidate.py +54 -0
- optpilot-0.2.0/src/optpilot/fixed_study.py +101 -0
- optpilot-0.2.0/src/optpilot/harbor_runner.py +230 -0
- optpilot-0.2.0/src/optpilot/host_env.py +129 -0
- optpilot-0.2.0/src/optpilot/image_reference.py +126 -0
- optpilot-0.2.0/src/optpilot/locked_python_runtime.py +910 -0
- optpilot-0.2.0/src/optpilot/locked_python_runtime_contract.py +281 -0
- optpilot-0.2.0/src/optpilot/method_exchange_projection.py +531 -0
- optpilot-0.2.0/src/optpilot/method_launch_environment.py +349 -0
- optpilot-0.2.0/src/optpilot/method_protocol_limits.py +29 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/methods.py +0 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/models.py +60 -1
- optpilot-0.2.0/src/optpilot/package_index.py +508 -0
- optpilot-0.2.0/src/optpilot/package_settings.py +432 -0
- optpilot-0.2.0/src/optpilot/package_validation.py +1258 -0
- optpilot-0.2.0/src/optpilot/parameter_run_harness.py +876 -0
- optpilot-0.2.0/src/optpilot/parameter_values.py +214 -0
- optpilot-0.2.0/src/optpilot/policy_validation.py +257 -0
- optpilot-0.2.0/src/optpilot/prepared_runtime_cache.py +1185 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/provenance.py +4 -1
- optpilot-0.2.0/src/optpilot/realm/__init__.py +8 -0
- optpilot-0.2.0/src/optpilot/realm/_container_web_gateway.py +197 -0
- optpilot-0.2.0/src/optpilot/realm/_local_attempt_worker.py +754 -0
- optpilot-0.2.0/src/optpilot/realm/_local_process_wrapper.py +868 -0
- optpilot-0.2.0/src/optpilot/realm/_sqlite_bootstrap.py +43 -0
- optpilot-0.2.0/src/optpilot/realm/_validation.py +87 -0
- optpilot-0.2.0/src/optpilot/realm/attempt_finalizer.py +532 -0
- optpilot-0.2.0/src/optpilot/realm/catalog_publication.py +1178 -0
- optpilot-0.2.0/src/optpilot/realm/catalog_service.py +407 -0
- optpilot-0.2.0/src/optpilot/realm/config.py +109 -0
- optpilot-0.2.0/src/optpilot/realm/configured_package_ingress.py +734 -0
- optpilot-0.2.0/src/optpilot/realm/configured_package_ingress_service.py +986 -0
- optpilot-0.2.0/src/optpilot/realm/content.py +2731 -0
- optpilot-0.2.0/src/optpilot/realm/editable_workspace_service.py +2430 -0
- optpilot-0.2.0/src/optpilot/realm/environment_preview.py +1339 -0
- optpilot-0.2.0/src/optpilot/realm/environment_preview_binding.py +3220 -0
- optpilot-0.2.0/src/optpilot/realm/ephemeral_volume_namespace.py +2056 -0
- optpilot-0.2.0/src/optpilot/realm/ephemeral_volume_records.py +414 -0
- optpilot-0.2.0/src/optpilot/realm/ephemeral_volume_service.py +1547 -0
- optpilot-0.2.0/src/optpilot/realm/errors.py +85 -0
- optpilot-0.2.0/src/optpilot/realm/evaluation_compiler.py +84 -0
- optpilot-0.2.0/src/optpilot/realm/execution_binding_records.py +1290 -0
- optpilot-0.2.0/src/optpilot/realm/filesystem_quota.py +61 -0
- optpilot-0.2.0/src/optpilot/realm/gc.py +1689 -0
- optpilot-0.2.0/src/optpilot/realm/inspection.py +97 -0
- optpilot-0.2.0/src/optpilot/realm/inspection_service.py +40 -0
- optpilot-0.2.0/src/optpilot/realm/interface_output_ledger.py +1933 -0
- optpilot-0.2.0/src/optpilot/realm/interface_output_records.py +565 -0
- optpilot-0.2.0/src/optpilot/realm/interface_output_service.py +709 -0
- optpilot-0.2.0/src/optpilot/realm/interface_outputs.py +590 -0
- optpilot-0.2.0/src/optpilot/realm/layered_volume_realization.py +649 -0
- optpilot-0.2.0/src/optpilot/realm/leases.py +110 -0
- optpilot-0.2.0/src/optpilot/realm/ledger.py +34452 -0
- optpilot-0.2.0/src/optpilot/realm/local_attempt_launcher.py +1260 -0
- optpilot-0.2.0/src/optpilot/realm/local_attempt_protocol.py +712 -0
- optpilot-0.2.0/src/optpilot/realm/local_capacity.py +273 -0
- optpilot-0.2.0/src/optpilot/realm/local_container_web_provider.py +2520 -0
- optpilot-0.2.0/src/optpilot/realm/local_process_attempt_provider.py +1460 -0
- optpilot-0.2.0/src/optpilot/realm/local_process_supervisor.py +3954 -0
- optpilot-0.2.0/src/optpilot/realm/local_runtime.py +597 -0
- optpilot-0.2.0/src/optpilot/realm/local_study_package.py +845 -0
- optpilot-0.2.0/src/optpilot/realm/manifests.py +355 -0
- optpilot-0.2.0/src/optpilot/realm/method_exchange_records.py +927 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0001_realm_core.sql +437 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0002_workspace_records.sql +330 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0003_run_admission.sql +1279 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0004_run_evaluation_closure.sql +301 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0005_run_retirement.sql +466 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0006_projection_lifecycle.sql +596 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0007_run_control_and_attempts.sql +1611 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0008_run_definitions.sql +428 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0009_owner_derivations.sql +559 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0010_study_definitions.sql +280 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0011_completed_tree_captures.sql +131 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0012_ephemeral_writable_volumes.sql +576 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0013_run_attempt_execution_bindings.sql +394 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0014_execution_launch_and_cleanup_authority.sql +360 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0015_run_attempt_loss_reconciliation.sql +655 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0016_method_exchange_checkpoints.sql +1286 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0017_operator_jobs.sql +928 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0018_run_hard_stop_escalation.sql +276 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0019_operator_capacity.sql +409 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0020_interface_output_sessions.sql +453 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0021_run_terminal_seals.sql +104 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0022_study_definition_semantic_reuse.sql +335 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0023_study_launch_handoffs.sql +572 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0024_catalog_package_revisions.sql +435 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0025_content_composition_bindings.sql +57 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0026_catalog_package_governance.sql +718 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0027_catalog_atomic_publication.sql +570 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0028_workspace_assembly.sql +359 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0029_configured_package_ingress.sql +1510 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0030_review_collections.sql +111 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0031_attachment_observation_anchors.sql +34 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0032_interface_output_session_resume.sql +74 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0033_workspace_metadata_revision.sql +25 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0034_selection_owner_adoptions.sql +70 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0035_provider_trust_policy.sql +239 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0036_provider_trust_contract.sql +279 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0037_run_deletion.sql +319 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/0038_method_exchange_failure_cause.sql +18 -0
- optpilot-0.2.0/src/optpilot/realm/migrations/__init__.py +1 -0
- optpilot-0.2.0/src/optpilot/realm/operator_attempt_binding.py +1711 -0
- optpilot-0.2.0/src/optpilot/realm/operator_capacity_ledger.py +973 -0
- optpilot-0.2.0/src/optpilot/realm/operator_capacity_records.py +345 -0
- optpilot-0.2.0/src/optpilot/realm/operator_job_ledger.py +2668 -0
- optpilot-0.2.0/src/optpilot/realm/operator_job_records.py +1418 -0
- optpilot-0.2.0/src/optpilot/realm/operator_job_service.py +4647 -0
- optpilot-0.2.0/src/optpilot/realm/owner_derivation.py +501 -0
- optpilot-0.2.0/src/optpilot/realm/owners.py +324 -0
- optpilot-0.2.0/src/optpilot/realm/process_execution_binder.py +2566 -0
- optpilot-0.2.0/src/optpilot/realm/process_provider.py +210 -0
- optpilot-0.2.0/src/optpilot/realm/projection.py +1045 -0
- optpilot-0.2.0/src/optpilot/realm/projection_namespace.py +1670 -0
- optpilot-0.2.0/src/optpilot/realm/projection_records.py +399 -0
- optpilot-0.2.0/src/optpilot/realm/projection_service.py +2842 -0
- optpilot-0.2.0/src/optpilot/realm/provider_trust_policy.py +208 -0
- optpilot-0.2.0/src/optpilot/realm/provider_trust_records.py +323 -0
- optpilot-0.2.0/src/optpilot/realm/refs.py +144 -0
- optpilot-0.2.0/src/optpilot/realm/review_collection_ledger.py +1283 -0
- optpilot-0.2.0/src/optpilot/realm/review_collection_service.py +717 -0
- optpilot-0.2.0/src/optpilot/realm/review_collections.py +780 -0
- optpilot-0.2.0/src/optpilot/realm/run_attempt_records.py +1261 -0
- optpilot-0.2.0/src/optpilot/realm/run_candidate_comparison.py +996 -0
- optpilot-0.2.0/src/optpilot/realm/run_candidate_evidence.py +207 -0
- optpilot-0.2.0/src/optpilot/realm/run_candidate_outcomes.py +602 -0
- optpilot-0.2.0/src/optpilot/realm/run_candidate_results.py +417 -0
- optpilot-0.2.0/src/optpilot/realm/run_catalog.py +165 -0
- optpilot-0.2.0/src/optpilot/realm/run_child.py +970 -0
- optpilot-0.2.0/src/optpilot/realm/run_child_service.py +401 -0
- optpilot-0.2.0/src/optpilot/realm/run_closure.py +2058 -0
- optpilot-0.2.0/src/optpilot/realm/run_comparability.py +265 -0
- optpilot-0.2.0/src/optpilot/realm/run_control_records.py +147 -0
- optpilot-0.2.0/src/optpilot/realm/run_definition.py +719 -0
- optpilot-0.2.0/src/optpilot/realm/run_deletion_service.py +240 -0
- optpilot-0.2.0/src/optpilot/realm/run_overview.py +385 -0
- optpilot-0.2.0/src/optpilot/realm/run_projection.py +462 -0
- optpilot-0.2.0/src/optpilot/realm/run_reader.py +407 -0
- optpilot-0.2.0/src/optpilot/realm/run_records.py +1366 -0
- optpilot-0.2.0/src/optpilot/realm/run_snapshot.py +1042 -0
- optpilot-0.2.0/src/optpilot/realm/run_terminal_seal.py +353 -0
- optpilot-0.2.0/src/optpilot/realm/run_timeline.py +302 -0
- optpilot-0.2.0/src/optpilot/realm/run_views.py +722 -0
- optpilot-0.2.0/src/optpilot/realm/run_workbench.py +1122 -0
- optpilot-0.2.0/src/optpilot/realm/selection_content_service.py +672 -0
- optpilot-0.2.0/src/optpilot/realm/selection_service.py +139 -0
- optpilot-0.2.0/src/optpilot/realm/selections.py +627 -0
- optpilot-0.2.0/src/optpilot/realm/service.py +660 -0
- optpilot-0.2.0/src/optpilot/realm/shortlist_service.py +801 -0
- optpilot-0.2.0/src/optpilot/realm/study_definition.py +308 -0
- optpilot-0.2.0/src/optpilot/realm/study_launch_records.py +766 -0
- optpilot-0.2.0/src/optpilot/realm/workspace_assembly.py +1277 -0
- optpilot-0.2.0/src/optpilot/realm/workspaces.py +750 -0
- optpilot-0.2.0/src/optpilot/realm_retained_batch_run_driver.py +1664 -0
- optpilot-0.2.0/src/optpilot/realm_run_execution_service.py +578 -0
- optpilot-0.2.0/src/optpilot/realm_study_runner.py +168 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/registry.py +0 -1
- optpilot-0.2.0/src/optpilot/resource_actions.py +612 -0
- optpilot-0.2.0/src/optpilot/resource_authoring.py +84 -0
- optpilot-0.2.0/src/optpilot/resource_commands.py +115 -0
- optpilot-0.2.0/src/optpilot/retained_batch_runtime.py +4447 -0
- optpilot-0.2.0/src/optpilot/retained_batch_worker.py +2958 -0
- optpilot-0.2.0/src/optpilot/retained_driver_factory.py +44 -0
- optpilot-0.2.0/src/optpilot/retained_file_candidates.py +790 -0
- optpilot-0.2.0/src/optpilot/retained_study_compiler.py +1881 -0
- optpilot-0.2.0/src/optpilot/retained_study_service.py +1334 -0
- optpilot-0.2.0/src/optpilot/run_attempt_heartbeat.py +484 -0
- optpilot-0.2.0/src/optpilot/run_attempt_scheduler.py +1253 -0
- optpilot-0.2.0/src/optpilot/run_authority.py +1200 -0
- optpilot-0.2.0/src/optpilot/run_control_manifest.py +649 -0
- optpilot-0.2.0/src/optpilot/run_controller.py +1235 -0
- optpilot-0.2.0/src/optpilot/run_controller_heartbeat.py +590 -0
- optpilot-0.2.0/src/optpilot/run_execution_profile.py +178 -0
- optpilot-0.2.0/src/optpilot/run_sources.py +90 -0
- optpilot-0.2.0/src/optpilot/run_terminal_policy.py +269 -0
- optpilot-0.2.0/src/optpilot/runner.py +232 -0
- optpilot-0.2.0/src/optpilot/runtime_binding.py +2792 -0
- optpilot-0.2.0/src/optpilot/runtime_limits.py +35 -0
- optpilot-0.2.0/src/optpilot/runtime_scopes.py +15 -0
- optpilot-0.2.0/src/optpilot/scheduler.py +372 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/schema_validation.py +13 -1
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/schemas/__init__.py +0 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/schemas/defs/candidate.schema.json +5 -0
- optpilot-0.2.0/src/optpilot/schemas/defs/common.schema.json +430 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/schemas/defs/metrics.schema.json +0 -0
- optpilot-0.2.0/src/optpilot/schemas/defs/runtime.schema.json +173 -0
- optpilot-0.2.0/src/optpilot/schemas/environment.schema.json +276 -0
- optpilot-0.2.0/src/optpilot/schemas/experiment.schema.json +719 -0
- optpilot-0.2.0/src/optpilot/schemas/method.schema.json +150 -0
- optpilot-0.2.0/src/optpilot/schemas/resource.schema.json +57 -0
- optpilot-0.2.0/src/optpilot/schemas/study.schema.json +158 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/setup.py +18 -4
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/spec.py +12 -3
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/storage.py +81 -7
- optpilot-0.2.0/src/optpilot/study_launch_ids.py +33 -0
- optpilot-0.2.0/src/optpilot/study_launch_service.py +1090 -0
- optpilot-0.2.0/src/optpilot/study_realm_compiler.py +949 -0
- optpilot-0.2.0/src/optpilot/task_vocabulary.py +122 -0
- {optpilot-0.1.0 → optpilot-0.2.0}/src/optpilot/worker.py +0 -0
- optpilot-0.2.0/src/optpilot.egg-info/SOURCES.txt +243 -0
- optpilot-0.1.0/MANIFEST.in +0 -9
- optpilot-0.1.0/PKG-INFO +0 -266
- optpilot-0.1.0/README.md +0 -236
- optpilot-0.1.0/src/optpilot/cli.py +0 -112
- optpilot-0.1.0/src/optpilot/container_utils.py +0 -120
- optpilot-0.1.0/src/optpilot/method_runtime.py +0 -831
- optpilot-0.1.0/src/optpilot/method_worker.py +0 -289
- optpilot-0.1.0/src/optpilot/package_index.py +0 -238
- optpilot-0.1.0/src/optpilot/package_validation.py +0 -136
- optpilot-0.1.0/src/optpilot/run_sources.py +0 -419
- optpilot-0.1.0/src/optpilot/runner.py +0 -454
- optpilot-0.1.0/src/optpilot/scheduler.py +0 -165
- optpilot-0.1.0/src/optpilot/schemas/defs/common.schema.json +0 -140
- optpilot-0.1.0/src/optpilot/schemas/defs/runtime.schema.json +0 -70
- optpilot-0.1.0/src/optpilot/schemas/environment.schema.json +0 -91
- optpilot-0.1.0/src/optpilot/schemas/method.schema.json +0 -67
- optpilot-0.1.0/src/optpilot/schemas/resource.schema.json +0 -16
- optpilot-0.1.0/src/optpilot/schemas/study.schema.json +0 -71
- optpilot-0.1.0/src/optpilot.egg-info/PKG-INFO +0 -266
- optpilot-0.1.0/src/optpilot.egg-info/SOURCES.txt +0 -47
- optpilot-0.1.0/src/optpilot.egg-info/dependency_links.txt +0 -1
- optpilot-0.1.0/src/optpilot.egg-info/entry_points.txt +0 -2
- optpilot-0.1.0/src/optpilot.egg-info/requires.txt +0 -11
- optpilot-0.1.0/src/optpilot.egg-info/top_level.txt +0 -1
- optpilot-0.1.0/tests/test_mvp.py +0 -5658
- {optpilot-0.1.0 → optpilot-0.2.0}/setup.cfg +0 -0
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
prune .agents
|
|
2
|
+
prune .github
|
|
3
|
+
prune catalog
|
|
4
|
+
prune design
|
|
5
|
+
prune designs
|
|
6
|
+
prune docs
|
|
7
|
+
prune website
|
|
8
|
+
prune resource
|
|
9
|
+
prune scripts
|
|
10
|
+
prune tests
|
|
11
|
+
prune test_catalog
|
|
12
|
+
prune .optpilot-ui
|
|
13
|
+
prune .pytest_cache
|
|
14
|
+
prune .venv
|
|
15
|
+
prune dist
|
|
16
|
+
prune site
|
|
17
|
+
prune runs
|
|
18
|
+
prune workspace
|
|
19
|
+
global-exclude .DS_Store
|
|
20
|
+
# Bytecode from whoever last ran the tests is not part of a distribution.
|
|
21
|
+
global-exclude *.pyc
|
|
22
|
+
global-exclude *.pyo
|
|
23
|
+
prune **/__pycache__
|
|
24
|
+
recursive-exclude . __pycache__
|
|
25
|
+
# Build metadata regenerated on every build; its file modes come from
|
|
26
|
+
# whatever filesystem built it, not from the repository.
|
|
27
|
+
prune src/optpilot.egg-info
|
|
28
|
+
global-exclude *.egg-info
|
|
29
|
+
prune desktop
|
optpilot-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: optpilot
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Versioned experiments for evaluating and improving candidate solutions
|
|
5
|
+
Author: OptPilot contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/MINDS-THU/OptPilot
|
|
8
|
+
Project-URL: Repository, https://github.com/MINDS-THU/OptPilot.git
|
|
9
|
+
Project-URL: Issues, https://github.com/MINDS-THU/OptPilot/issues
|
|
10
|
+
Keywords: optimization,experiments,evaluation,evidence,benchmarking
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: jsonschema>=4
|
|
21
|
+
Requires-Dist: PyYAML>=6.0
|
|
22
|
+
Requires-Dist: referencing>=0.30
|
|
23
|
+
Requires-Dist: tomli>=2; python_version < "3.11"
|
|
24
|
+
Provides-Extra: docs
|
|
25
|
+
Requires-Dist: mkdocs>=1.6; extra == "docs"
|
|
26
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
27
|
+
Provides-Extra: examples
|
|
28
|
+
Requires-Dist: job-shop-lib>=1.7.0; extra == "examples"
|
|
29
|
+
Requires-Dist: stable-baselines3<3,>=2.3; extra == "examples"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# OptPilot
|
|
33
|
+
|
|
34
|
+
An optimization score is useful only when you can tell what produced it. The candidate, objective, evaluation cases, metric and run conditions all shape the result. Change one of them and a score may no longer support a fair comparison.
|
|
35
|
+
|
|
36
|
+
OptPilot makes those conditions explicit and keeps them with the observations, failures and evidence from each run. Review freezes the selected project versions before execution. The resulting record lets you inspect what was measured, compare candidates under shared conditions, and resume interrupted work without losing completed trials.
|
|
37
|
+
|
|
38
|
+
OptPilot Core is an open-source Python package and CLI for versioned experiments. Define the evaluation in `optpilot.experiment.yaml`, review the exact input versions, and use the CLI to run the evaluation and inspect its evidence.
|
|
39
|
+
|
|
40
|
+
Use Python 3.10 or newer to install Core. The first experiment walks through a comparison and shows how to trace a score to its inputs. [Installation](docs/installation.md) · [First experiment](docs/getting-started.md)
|
|
41
|
+
|
|
42
|
+
The [factory dispatch example](catalog/asteria_factory/) compares three rules in a simulated three-floor production facility on matched random seeds. It reports throughput and on-time delivery separately.
|
|
43
|
+
|
|
44
|
+
## What OptPilot records
|
|
45
|
+
|
|
46
|
+
- The exact saved versions selected for evaluation, so later source edits do not silently change a reviewed experiment.
|
|
47
|
+
- Per-trial inputs, metric values, failures and supporting evidence. A measured zero remains distinct from a missing score or failed attempt.
|
|
48
|
+
- Repetitions, retries and generated candidates under the same reviewed conditions. An interrupted run can resume with its original identity and completed trials.
|
|
49
|
+
- Resource requirements, reservations and usage receipts when an experiment needs registered resources.
|
|
50
|
+
|
|
51
|
+
The experiment author chooses representative cases and a grading contract that measures the intended objective.
|
|
52
|
+
|
|
53
|
+
## Execution options
|
|
54
|
+
|
|
55
|
+
Run trusted Python graders locally or on a registered SSH worker, use Harbor for Docker-backed agent evaluations, or record operator measurements. Core can also import external results with explicit bindings to reviewed versions and retain the source job and trial identities. [Choosing a runner](docs/capabilities.md)
|
|
56
|
+
|
|
57
|
+
## Learn more
|
|
58
|
+
|
|
59
|
+
[Project website](https://minds-thu.github.io/OptPilot/) · [Technical documentation](https://minds-thu.github.io/OptPilot/reference/) · [First experiment](docs/getting-started.md) · [Experiment model](docs/concepts.md) · [Configuration](docs/configuration.md) · [Contributing](docs/development.md)
|
optpilot-0.2.0/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# OptPilot
|
|
2
|
+
|
|
3
|
+
An optimization score is useful only when you can tell what produced it. The candidate, objective, evaluation cases, metric and run conditions all shape the result. Change one of them and a score may no longer support a fair comparison.
|
|
4
|
+
|
|
5
|
+
OptPilot makes those conditions explicit and keeps them with the observations, failures and evidence from each run. Review freezes the selected project versions before execution. The resulting record lets you inspect what was measured, compare candidates under shared conditions, and resume interrupted work without losing completed trials.
|
|
6
|
+
|
|
7
|
+
OptPilot Core is an open-source Python package and CLI for versioned experiments. Define the evaluation in `optpilot.experiment.yaml`, review the exact input versions, and use the CLI to run the evaluation and inspect its evidence.
|
|
8
|
+
|
|
9
|
+
Use Python 3.10 or newer to install Core. The first experiment walks through a comparison and shows how to trace a score to its inputs. [Installation](docs/installation.md) · [First experiment](docs/getting-started.md)
|
|
10
|
+
|
|
11
|
+
The [factory dispatch example](catalog/asteria_factory/) compares three rules in a simulated three-floor production facility on matched random seeds. It reports throughput and on-time delivery separately.
|
|
12
|
+
|
|
13
|
+
## What OptPilot records
|
|
14
|
+
|
|
15
|
+
- The exact saved versions selected for evaluation, so later source edits do not silently change a reviewed experiment.
|
|
16
|
+
- Per-trial inputs, metric values, failures and supporting evidence. A measured zero remains distinct from a missing score or failed attempt.
|
|
17
|
+
- Repetitions, retries and generated candidates under the same reviewed conditions. An interrupted run can resume with its original identity and completed trials.
|
|
18
|
+
- Resource requirements, reservations and usage receipts when an experiment needs registered resources.
|
|
19
|
+
|
|
20
|
+
The experiment author chooses representative cases and a grading contract that measures the intended objective.
|
|
21
|
+
|
|
22
|
+
## Execution options
|
|
23
|
+
|
|
24
|
+
Run trusted Python graders locally or on a registered SSH worker, use Harbor for Docker-backed agent evaluations, or record operator measurements. Core can also import external results with explicit bindings to reviewed versions and retain the source job and trial identities. [Choosing a runner](docs/capabilities.md)
|
|
25
|
+
|
|
26
|
+
## Learn more
|
|
27
|
+
|
|
28
|
+
[Project website](https://minds-thu.github.io/OptPilot/) · [Technical documentation](https://minds-thu.github.io/OptPilot/reference/) · [First experiment](docs/getting-started.md) · [Experiment model](docs/concepts.md) · [Configuration](docs/configuration.md) · [Contributing](docs/development.md)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "optpilot"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Versioned experiments for evaluating and improving candidate solutions"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = "Apache-2.0"
|
|
@@ -32,6 +32,7 @@ dependencies = [
|
|
|
32
32
|
"jsonschema>=4",
|
|
33
33
|
"PyYAML>=6.0",
|
|
34
34
|
"referencing>=0.30",
|
|
35
|
+
"tomli>=2; python_version < '3.11'",
|
|
35
36
|
]
|
|
36
37
|
|
|
37
38
|
[project.optional-dependencies]
|
|
@@ -63,16 +64,19 @@ Issues = "https://github.com/MINDS-THU/OptPilot/issues"
|
|
|
63
64
|
optpilot = "optpilot.cli:main"
|
|
64
65
|
|
|
65
66
|
[tool.setuptools]
|
|
67
|
+
# The Core distribution contains the optpilot package under src/.
|
|
68
|
+
# Tutorial projects and test fixtures run from a source checkout.
|
|
66
69
|
package-dir = {"" = "src"}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
packages = [
|
|
71
|
+
"optpilot",
|
|
72
|
+
"optpilot.authoring",
|
|
73
|
+
"optpilot.realm",
|
|
74
|
+
"optpilot.realm.migrations",
|
|
75
|
+
"optpilot.schemas",
|
|
76
|
+
"optpilot.schemas.defs",
|
|
77
|
+
]
|
|
70
78
|
|
|
71
79
|
[tool.setuptools.package-data]
|
|
80
|
+
"optpilot" = ["authoring/contract.json", "authoring/optpilot-evaluation/SKILL.md"]
|
|
72
81
|
"optpilot.schemas" = ["*.json", "defs/*.json"]
|
|
73
|
-
|
|
74
|
-
[tool.uv.workspace]
|
|
75
|
-
members = ["studio"]
|
|
76
|
-
|
|
77
|
-
[tool.uv.sources]
|
|
78
|
-
optpilot = { workspace = true }
|
|
82
|
+
"optpilot.realm" = ["migrations/*.sql"]
|
|
File without changes
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""Read a project manifest and register its exact content and dependency versions."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path, PurePosixPath
|
|
6
|
+
|
|
7
|
+
import hashlib
|
|
8
|
+
import re
|
|
9
|
+
|
|
10
|
+
import jsonschema
|
|
11
|
+
import yaml
|
|
12
|
+
|
|
13
|
+
from ._experiment_store import database, metric_names, persist_version, transaction, version_info, version_row
|
|
14
|
+
from .parameter_values import apply_parameter_defaults, validate_parameter_values
|
|
15
|
+
from .realm.refs import BlobRef, canonical_json_bytes
|
|
16
|
+
from .schema_validation import validate_experiment_schema
|
|
17
|
+
|
|
18
|
+
MANIFEST = "optpilot.experiment.yaml"
|
|
19
|
+
DRAFT_MARKER = ".optpilot-artifact-draft.json"
|
|
20
|
+
GROUPS = {"environments": "environment", "tasks": "task", "instances": "instance",
|
|
21
|
+
"suites": "suite", "candidates": "candidate", "generators": "generator"}
|
|
22
|
+
MAX_FILE_BYTES = 32 * 1024 * 1024
|
|
23
|
+
MAX_ARTIFACT_BYTES = 128 * 1024 * 1024
|
|
24
|
+
INTERFACE_PATH = re.compile(r"/[A-Za-z0-9_./~-]*\Z")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def object_value(value, label):
|
|
28
|
+
if not isinstance(value, dict) or not all(isinstance(k, str) for k in value):
|
|
29
|
+
raise ValueError(f"{label} must be an object with string keys.")
|
|
30
|
+
return value
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def text_value(value, label):
|
|
34
|
+
if not isinstance(value, str) or not value.strip():
|
|
35
|
+
raise ValueError(f"{label} must be a nonempty string.")
|
|
36
|
+
return value
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def string_list(value, label, *, nonempty=False):
|
|
40
|
+
if not isinstance(value, list) or (nonempty and not value):
|
|
41
|
+
raise ValueError(f"{label} must be {'a nonempty' if nonempty else 'an'} array.")
|
|
42
|
+
for item in value:
|
|
43
|
+
text_value(item, label)
|
|
44
|
+
if len(set(value)) != len(value):
|
|
45
|
+
raise ValueError(f"{label} contains a duplicate.")
|
|
46
|
+
return value
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def safe_path(value):
|
|
50
|
+
name = text_value(value, "file path")
|
|
51
|
+
path = PurePosixPath(name)
|
|
52
|
+
if path.is_absolute() or any(part in ("", ".", "..") for part in name.split("/")) or "\\" in name or ":" in name:
|
|
53
|
+
raise ValueError(f"Expected a relative project file, got {name!r}.")
|
|
54
|
+
return path
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def read_file(root, name):
|
|
58
|
+
subpath = safe_path(name)
|
|
59
|
+
path = root
|
|
60
|
+
for part in subpath.parts:
|
|
61
|
+
path = path / part
|
|
62
|
+
if path.is_symlink():
|
|
63
|
+
raise ValueError(f"Symlinks cannot be frozen as project files: {subpath}")
|
|
64
|
+
if not path.is_file() or path.stat().st_size > MAX_FILE_BYTES:
|
|
65
|
+
raise ValueError(f"Missing or oversized project file: {subpath}")
|
|
66
|
+
with path.open("rb") as stream:
|
|
67
|
+
data = stream.read(MAX_FILE_BYTES + 1)
|
|
68
|
+
if len(data) > MAX_FILE_BYTES:
|
|
69
|
+
raise ValueError(f"Oversized project file: {subpath}")
|
|
70
|
+
return data
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def entry_file(value):
|
|
74
|
+
filename, sep, function = text_value(value, "Python entrypoint").rpartition(":")
|
|
75
|
+
if not sep or not filename.endswith(".py") or not function.isidentifier():
|
|
76
|
+
raise ValueError(f"Expected a Python entrypoint such as 'grader.py:evaluate', got {value!r}.")
|
|
77
|
+
return str(safe_path(filename))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def parameter_schema(value, label):
|
|
81
|
+
schema = object_value(value, label)
|
|
82
|
+
defaults = apply_parameter_defaults({}, schema)
|
|
83
|
+
for name, item in defaults.items():
|
|
84
|
+
checked_values({name: item}, {name: schema[name]}, label)
|
|
85
|
+
return schema
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def checked_values(values, schema, label):
|
|
89
|
+
values = object_value(values, label)
|
|
90
|
+
resolved = apply_parameter_defaults(values, schema)
|
|
91
|
+
errors = validate_parameter_values(resolved, schema, location=label)
|
|
92
|
+
if errors:
|
|
93
|
+
raise ValueError(" ".join(errors))
|
|
94
|
+
return resolved
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def validate_contract(spec):
|
|
98
|
+
contract = object_value(spec.get("decisionContract"), "decisionContract")
|
|
99
|
+
if spec.get("runner") == "harbor":
|
|
100
|
+
if contract.get("format") != "agent" or not spec.get("harborTask"):
|
|
101
|
+
raise ValueError("A Harbor Task needs an agent contract and a local harborTask directory.")
|
|
102
|
+
if set(spec) & {"parameters", "environment", "evaluator", "isolation", "environmentParameters", "feedbackMetrics"}:
|
|
103
|
+
raise ValueError("A Harbor Task package owns the environment, grading and task settings.")
|
|
104
|
+
elif spec.get("runner") == "manual":
|
|
105
|
+
if contract.get("format") != "parameters" or {"evaluator", "harborTask", "isolation"} & set(spec):
|
|
106
|
+
raise ValueError("A manual Task accepts parameters and a human metric receipt.")
|
|
107
|
+
elif "harborTask" in spec or contract.get("format") not in ("parameters", "program"):
|
|
108
|
+
raise ValueError("decisionContract.format must be parameters or program.")
|
|
109
|
+
if "schema" in contract:
|
|
110
|
+
if contract["format"] != "parameters":
|
|
111
|
+
raise ValueError("Only a parameters decision contract declares a parameter schema.")
|
|
112
|
+
parameter_schema(contract["schema"], "decisionContract.schema")
|
|
113
|
+
for direction in ("input", "output"):
|
|
114
|
+
if direction in contract:
|
|
115
|
+
if contract["format"] != "program":
|
|
116
|
+
raise ValueError(f"Only a program contract declares an {direction} call schema.")
|
|
117
|
+
try:
|
|
118
|
+
jsonschema.Draft202012Validator.check_schema(contract[direction])
|
|
119
|
+
except jsonschema.SchemaError as exc:
|
|
120
|
+
raise ValueError(f"Invalid program {direction} schema: {exc.message}") from exc
|
|
121
|
+
names = string_list(metric_names(spec), "metrics")
|
|
122
|
+
feedback = string_list(spec.get("feedbackMetrics", []), "feedbackMetrics")
|
|
123
|
+
if set(feedback) - set(names):
|
|
124
|
+
raise ValueError("feedbackMetrics must refer to declared Task metrics.")
|
|
125
|
+
schema = parameter_schema(spec.get("parameters", {}), "Task.parameters")
|
|
126
|
+
mapping = object_value(spec.get("environmentParameters", {}), "environmentParameters")
|
|
127
|
+
if any(not isinstance(v, str) or v not in schema for v in mapping.values()):
|
|
128
|
+
raise ValueError("environmentParameters must refer to declared Task parameters.")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def prepare_one(root, kind, raw, by_artifact, *, provenance=None):
|
|
132
|
+
artifact = text_value(raw.get("id"), f"{kind}.id")
|
|
133
|
+
if artifact in by_artifact:
|
|
134
|
+
raise ValueError(f"Duplicate artifact id {artifact!r}.")
|
|
135
|
+
name = text_value(raw.get("name", artifact), f"{kind}.name")
|
|
136
|
+
spec = dict(raw, kind=kind, id=artifact, name=name, dependencies=[])
|
|
137
|
+
if "resourceRequirements" in spec:
|
|
138
|
+
from .experiment_resource_plan import validate_requirements
|
|
139
|
+
validate_requirements(spec)
|
|
140
|
+
paths = list(string_list(spec.pop("files", []), f"{artifact}.files"))
|
|
141
|
+
def dependency(ref, expected):
|
|
142
|
+
match = by_artifact.get(text_value(ref, f"{artifact}.{expected}"))
|
|
143
|
+
if not match or match[1]["kind"] != expected:
|
|
144
|
+
raise ValueError(f"{artifact!r} refers to missing {expected} {ref!r}.")
|
|
145
|
+
spec["dependencies"].append(match[0])
|
|
146
|
+
return match[1]
|
|
147
|
+
if kind == "environment":
|
|
148
|
+
object_value(spec.get("settings", {}), "Environment.settings")
|
|
149
|
+
if "interface" in spec:
|
|
150
|
+
interface = spec["interface"]
|
|
151
|
+
script = str(safe_path(interface["entrypoint"]))
|
|
152
|
+
if not script.endswith(".py"):
|
|
153
|
+
raise ValueError("Environment.interface.entrypoint must be a Python script.")
|
|
154
|
+
for key in ("path", "readyPath"):
|
|
155
|
+
target = interface.get(key, "/")
|
|
156
|
+
if (not INTERFACE_PATH.fullmatch(target) or "//" in target
|
|
157
|
+
or {".", ".."}.intersection(target.split("/"))):
|
|
158
|
+
raise ValueError(f"Environment.interface.{key} must be a local HTTP path.")
|
|
159
|
+
paths.extend([script, *interface.get("files", [])])
|
|
160
|
+
for prefix in interface.get("filePrefixes", []):
|
|
161
|
+
prefix = str(safe_path(prefix)) + "/"
|
|
162
|
+
if not any(path.startswith(prefix) for path in paths):
|
|
163
|
+
raise ValueError(f"No frozen environment file belongs to {prefix!r}.")
|
|
164
|
+
if kind == "task":
|
|
165
|
+
validate_contract(spec)
|
|
166
|
+
if spec.get("runner") == "harbor":
|
|
167
|
+
from .harbor_runner import package_files
|
|
168
|
+
paths.extend(package_files(root, spec["harborTask"]))
|
|
169
|
+
elif spec.get("runner") != "manual":
|
|
170
|
+
paths.append(entry_file(spec.get("evaluator")))
|
|
171
|
+
if "environment" in spec:
|
|
172
|
+
dependency(spec["environment"], "environment")
|
|
173
|
+
elif spec.get("environmentParameters"):
|
|
174
|
+
raise ValueError("environmentParameters requires an Environment.")
|
|
175
|
+
if kind == "instance":
|
|
176
|
+
task = dependency(spec.get("task"), "task")
|
|
177
|
+
spec["parameters"] = checked_values(spec.get("parameters", {}), task.get("parameters", {}), artifact)
|
|
178
|
+
object_value(spec.get("private", {}), "Instance.private")
|
|
179
|
+
if task.get("runner") == "harbor" and (paths or spec.get("private")):
|
|
180
|
+
raise ValueError("Harbor Instance data must be included in the frozen Task package.")
|
|
181
|
+
if kind == "suite":
|
|
182
|
+
for member in string_list(spec.get("instances"), f"{artifact}.instances", nonempty=True):
|
|
183
|
+
dependency(member, "instance")
|
|
184
|
+
if kind == "candidate" and spec["format"] == "agent" and paths:
|
|
185
|
+
raise ValueError("This Harbor agent configuration supports a built-in agent and optional model name.")
|
|
186
|
+
if "entrypoint" in spec:
|
|
187
|
+
paths.append(entry_file(spec["entrypoint"]))
|
|
188
|
+
content = {}
|
|
189
|
+
file_refs = {}
|
|
190
|
+
size = 0
|
|
191
|
+
for path in sorted(set(paths)):
|
|
192
|
+
data = read_file(root, path)
|
|
193
|
+
size += len(data)
|
|
194
|
+
if size > MAX_ARTIFACT_BYTES:
|
|
195
|
+
raise ValueError(f"Declared files of {artifact!r} exceed the artifact size limit.")
|
|
196
|
+
ref = str(BlobRef.from_bytes(data))
|
|
197
|
+
content[ref] = data
|
|
198
|
+
file_refs[path] = ref
|
|
199
|
+
executable = sorted(path for path in file_refs if (root / path).stat().st_mode & 0o111)
|
|
200
|
+
if executable:
|
|
201
|
+
spec["executableFiles"] = executable
|
|
202
|
+
spec["fileRefs"] = file_refs
|
|
203
|
+
spec.update(provenance or {})
|
|
204
|
+
return spec, content
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def freeze_one(root, db, kind, raw, by_artifact, *, provenance=None):
|
|
208
|
+
spec, content = prepare_one(root, kind, raw, by_artifact, provenance=provenance)
|
|
209
|
+
vid = persist_version(db, spec, content)
|
|
210
|
+
by_artifact[spec["id"]] = (vid, spec)
|
|
211
|
+
return version_info(version_row(db, vid))
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def read_manifest(root):
|
|
215
|
+
manifest = root / MANIFEST
|
|
216
|
+
data = {}
|
|
217
|
+
manifest_digest = None
|
|
218
|
+
if manifest.exists() or manifest.is_symlink():
|
|
219
|
+
try:
|
|
220
|
+
raw_manifest = read_file(root, MANIFEST)
|
|
221
|
+
manifest_digest = hashlib.sha256(raw_manifest).hexdigest()
|
|
222
|
+
data = yaml.safe_load(raw_manifest)
|
|
223
|
+
except yaml.YAMLError as exc:
|
|
224
|
+
raise ValueError(f"Invalid {MANIFEST}: {exc}") from exc
|
|
225
|
+
data = object_value(data, MANIFEST)
|
|
226
|
+
try:
|
|
227
|
+
canonical_json_bytes(data)
|
|
228
|
+
except (TypeError, ValueError) as exc:
|
|
229
|
+
raise ValueError(f"{MANIFEST} must contain finite JSON-compatible values.") from exc
|
|
230
|
+
validate_experiment_schema(data)
|
|
231
|
+
return data, manifest_digest
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def has_artifact_draft(root):
|
|
235
|
+
marker = Path(root) / DRAFT_MARKER
|
|
236
|
+
return marker.exists() or marker.is_symlink()
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def catalog(root, db):
|
|
240
|
+
root = Path(root).resolve()
|
|
241
|
+
if has_artifact_draft(root):
|
|
242
|
+
from ._experiment_draft import draft_catalog
|
|
243
|
+
return draft_catalog(root, db)
|
|
244
|
+
data, manifest_digest = read_manifest(root)
|
|
245
|
+
found = {"versions": [], "studies": data.get("studies", [])}
|
|
246
|
+
by_artifact = {}
|
|
247
|
+
for group, kind in GROUPS.items():
|
|
248
|
+
items = data.get(group, [])
|
|
249
|
+
found[group] = [freeze_one(root, db, kind, raw, by_artifact) for raw in items]
|
|
250
|
+
found["versions"].extend(found[group])
|
|
251
|
+
if manifest_digest:
|
|
252
|
+
db.executemany("INSERT OR IGNORE INTO version_manifests(version,digest) VALUES (?,?)",
|
|
253
|
+
((version["id"], manifest_digest) for version in found["versions"]))
|
|
254
|
+
return found
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def discover(root, store):
|
|
258
|
+
with database(store) as db, transaction(db):
|
|
259
|
+
return catalog(root, db)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def save(root, store, artifact_id):
|
|
263
|
+
if has_artifact_draft(root):
|
|
264
|
+
raise ValueError("Use Save as new version for an artifact draft.")
|
|
265
|
+
with database(store) as db, transaction(db):
|
|
266
|
+
available = catalog(root, db)
|
|
267
|
+
chosen = next((v for v in available["versions"] if artifact_id in (v["id"], v["artifactId"])), None)
|
|
268
|
+
if chosen is None:
|
|
269
|
+
raise ValueError(f"No current artifact {artifact_id!r} in this working directory.")
|
|
270
|
+
return version_info(version_row(db, chosen["id"]))
|
|
271
|
+
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""Materialize an immutable artifact as an isolated, explicitly saved draft."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from difflib import unified_diff
|
|
6
|
+
import json
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from shutil import rmtree
|
|
9
|
+
|
|
10
|
+
import yaml
|
|
11
|
+
|
|
12
|
+
from ._experiment_catalog import (DRAFT_MARKER, GROUPS, MANIFEST, entry_file, prepare_one,
|
|
13
|
+
read_file, read_manifest, safe_path)
|
|
14
|
+
from ._experiment_store import (database, derivation_info, encode, materialize, now,
|
|
15
|
+
persist_version, transaction, version_info, version_row, version_spec)
|
|
16
|
+
from .realm.refs import request_digest
|
|
17
|
+
|
|
18
|
+
_GROUP = {kind: group for group, kind in GROUPS.items()}
|
|
19
|
+
_GENERATED = {"generatorVersionId", "generatedByRunId", "generationId"}
|
|
20
|
+
_INTERNAL = _GENERATED | {"kind", "dependencies", "fileRefs", "executableFiles", "private"}
|
|
21
|
+
_DIFF_BUDGET = 96 * 1024
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _authorable(spec):
|
|
25
|
+
raw = {k: v for k, v in spec.items() if k not in _INTERNAL}
|
|
26
|
+
paths = set(spec["fileRefs"])
|
|
27
|
+
for field in ("entrypoint", "evaluator"):
|
|
28
|
+
if spec.get(field):
|
|
29
|
+
paths.discard(entry_file(spec[field]))
|
|
30
|
+
if spec.get("runner") == "harbor":
|
|
31
|
+
prefix = spec["harborTask"] + "/"
|
|
32
|
+
paths = {path for path in paths if not path.startswith(prefix)}
|
|
33
|
+
if paths:
|
|
34
|
+
raw["files"] = sorted(paths)
|
|
35
|
+
return raw
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _check_paths(paths):
|
|
39
|
+
for path in paths:
|
|
40
|
+
if safe_path(path).parts[0] in {MANIFEST, DRAFT_MARKER}:
|
|
41
|
+
raise ValueError(f"Artifact file {path!r} conflicts with a draft metadata file.")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def checkout(store, version_id, destination):
|
|
45
|
+
destination = Path(destination)
|
|
46
|
+
if destination.name in {"", ".", ".."}:
|
|
47
|
+
raise ValueError("Choose a new draft directory.")
|
|
48
|
+
destination = destination.parent.resolve(strict=True) / destination.name
|
|
49
|
+
with database(store) as db:
|
|
50
|
+
base = version_spec(db, version_id)
|
|
51
|
+
paths = sorted(base["fileRefs"])
|
|
52
|
+
_check_paths(paths)
|
|
53
|
+
destination.mkdir(mode=0o700)
|
|
54
|
+
try:
|
|
55
|
+
materialize(db, destination, [base])
|
|
56
|
+
manifest = {_GROUP[base["kind"]]: [_authorable(base)]}
|
|
57
|
+
(destination / MANIFEST).write_text(yaml.safe_dump(manifest, sort_keys=False, allow_unicode=True), encoding="utf-8")
|
|
58
|
+
(destination / DRAFT_MARKER).write_text(encode({"baseVersionId": version_id}), encoding="utf-8")
|
|
59
|
+
except BaseException:
|
|
60
|
+
rmtree(destination)
|
|
61
|
+
raise
|
|
62
|
+
preferred = next((entry_file(base[field]) for field in ("entrypoint", "evaluator") if base.get(field)), None)
|
|
63
|
+
if base.get("runner") == "harbor":
|
|
64
|
+
preferred = base["harborTask"] + "/instruction.md"
|
|
65
|
+
return {"versionId": version_id, "files": [MANIFEST, *paths],
|
|
66
|
+
"preferredFile": preferred or next(iter(paths), MANIFEST)}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _base_id(root):
|
|
70
|
+
marker = json.loads(read_file(root, DRAFT_MARKER))
|
|
71
|
+
if not isinstance(marker, dict) or not isinstance(marker.get("baseVersionId"), str):
|
|
72
|
+
raise ValueError("The draft has no valid saved base version.")
|
|
73
|
+
return marker["baseVersionId"]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def draft_catalog(root, db):
|
|
77
|
+
# Browse and review resolve authored ids to saved versions in a draft.
|
|
78
|
+
# Publishing working bytes always requires an explicit derived save.
|
|
79
|
+
found = {key: [] for key in [*GROUPS, "studies", "versions"]}
|
|
80
|
+
pending = [_base_id(root)]
|
|
81
|
+
seen = set()
|
|
82
|
+
while pending:
|
|
83
|
+
version_id = pending.pop()
|
|
84
|
+
if version_id in seen:
|
|
85
|
+
continue
|
|
86
|
+
seen.add(version_id)
|
|
87
|
+
version = version_info(version_row(db, version_id))
|
|
88
|
+
found[_GROUP[version["kind"]]].append(version)
|
|
89
|
+
found["versions"].append(version)
|
|
90
|
+
pending.extend(version["dependencies"])
|
|
91
|
+
return found
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _content_identity(spec):
|
|
95
|
+
# A generator receipt describes who produced the base. It is not part of
|
|
96
|
+
# the authored candidate or a claim about who edited the new draft.
|
|
97
|
+
result = {k: v for k, v in spec.items() if k not in _GENERATED}
|
|
98
|
+
if "generatorVersionId" in spec:
|
|
99
|
+
result["dependencies"] = [v for v in spec["dependencies"] if v != spec["generatorVersionId"]]
|
|
100
|
+
return result
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _capture(root, db, version_id):
|
|
104
|
+
root = Path(root).resolve()
|
|
105
|
+
if _base_id(root) != version_id:
|
|
106
|
+
raise ValueError("This draft belongs to a different saved base version.")
|
|
107
|
+
base = version_spec(db, version_id)
|
|
108
|
+
group = _GROUP[base["kind"]]
|
|
109
|
+
manifest, manifest_digest = read_manifest(root)
|
|
110
|
+
entries = manifest.get(group, [])
|
|
111
|
+
if len(entries) != 1 or entries[0]["id"] != base["id"] or any(
|
|
112
|
+
manifest.get(other) for other in [*GROUPS, "studies"] if other != group
|
|
113
|
+
):
|
|
114
|
+
raise ValueError("A draft must describe only the artifact it was opened from.")
|
|
115
|
+
raw = dict(entries[0])
|
|
116
|
+
if "private" in raw:
|
|
117
|
+
raise ValueError("Grader-only values are pinned to the base and cannot be edited in this draft.")
|
|
118
|
+
if "private" in base:
|
|
119
|
+
raw["private"] = base["private"]
|
|
120
|
+
pinned = {}
|
|
121
|
+
for dep_id in _content_identity(base)["dependencies"]:
|
|
122
|
+
dep = version_spec(db, dep_id)
|
|
123
|
+
pinned[dep["id"]] = (dep_id, dep)
|
|
124
|
+
spec, content = prepare_one(root, base["kind"], raw, pinned)
|
|
125
|
+
_check_paths(spec["fileRefs"])
|
|
126
|
+
return base, spec, content, manifest_digest
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _text_diff(path, old, new, budget):
|
|
130
|
+
if not budget or len(old) + len(new) > min(budget, 32 * 1024) or b"\0" in old or b"\0" in new:
|
|
131
|
+
return None
|
|
132
|
+
try:
|
|
133
|
+
before, after = (data.decode("utf-8").splitlines(keepends=True) for data in (old, new))
|
|
134
|
+
except UnicodeDecodeError:
|
|
135
|
+
return None
|
|
136
|
+
if len(before) + len(after) > 500:
|
|
137
|
+
return None
|
|
138
|
+
def terminated(lines):
|
|
139
|
+
return [line if line.endswith("\n") else line + "\n\\n" for line in lines]
|
|
140
|
+
diff = "".join(unified_diff(terminated(before), terminated(after), f"a/{path}", f"b/{path}"))
|
|
141
|
+
return diff if diff and len(diff.encode()) <= budget else None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _changes(db, base, spec, content):
|
|
145
|
+
changes = []
|
|
146
|
+
budget = _DIFF_BUDGET
|
|
147
|
+
|
|
148
|
+
def append(path, kind, old, new):
|
|
149
|
+
nonlocal budget
|
|
150
|
+
change = {"path": path, "kind": kind}
|
|
151
|
+
diff = _text_diff(path, old, new, budget)
|
|
152
|
+
if diff:
|
|
153
|
+
change["diff"] = diff
|
|
154
|
+
budget -= len(diff.encode())
|
|
155
|
+
changes.append(change)
|
|
156
|
+
|
|
157
|
+
def definition(s):
|
|
158
|
+
raw = _authorable(s)
|
|
159
|
+
raw.pop("files", None)
|
|
160
|
+
deps = _content_identity(s)["dependencies"]
|
|
161
|
+
if deps:
|
|
162
|
+
raw["dependencies"] = deps
|
|
163
|
+
return yaml.safe_dump(raw, allow_unicode=True).encode()
|
|
164
|
+
|
|
165
|
+
before, after = definition(base), definition(spec)
|
|
166
|
+
if before != after:
|
|
167
|
+
append(MANIFEST, "modified", before, after)
|
|
168
|
+
old_files, new_files = base["fileRefs"], spec["fileRefs"]
|
|
169
|
+
old_exec, new_exec = (set(s.get("executableFiles", [])) for s in (base, spec))
|
|
170
|
+
for path in sorted(old_files.keys() | new_files.keys()):
|
|
171
|
+
old, new = old_files.get(path), new_files.get(path)
|
|
172
|
+
if old != new:
|
|
173
|
+
previous = db.execute("SELECT bytes FROM blobs WHERE id=?", (old,)).fetchone()[0] if old else b""
|
|
174
|
+
append(path, "added" if old is None else "deleted" if new is None else "modified",
|
|
175
|
+
previous, content[new] if new else b"")
|
|
176
|
+
elif (path in old_exec) != (path in new_exec):
|
|
177
|
+
changes.append({"path": path, "kind": "modified",
|
|
178
|
+
"diff": "Executable permission added." if path in new_exec else "Executable permission removed."})
|
|
179
|
+
return changes
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def draft_diff(root, store, version_id):
|
|
183
|
+
with database(store) as db:
|
|
184
|
+
base, spec, content, _ = _capture(root, db, version_id)
|
|
185
|
+
changes = _changes(db, base, spec, content)
|
|
186
|
+
digest = request_digest(spec)
|
|
187
|
+
return {"changed": digest != request_digest(_content_identity(base)), "digest": digest, "changes": changes}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def save_derived(root, store, version_id, digest, summary):
|
|
191
|
+
if not isinstance(summary, str) or len(summary) > 4000:
|
|
192
|
+
raise ValueError("A change summary must be at most 4000 characters.")
|
|
193
|
+
with database(store) as db, transaction(db):
|
|
194
|
+
base, spec, content, manifest_digest = _capture(root, db, version_id)
|
|
195
|
+
if request_digest(spec) != digest:
|
|
196
|
+
raise ValueError("The draft changed after review. Review the differences again.")
|
|
197
|
+
changed = digest != request_digest(_content_identity(base))
|
|
198
|
+
target = "v-" + digest if changed else version_id
|
|
199
|
+
existing = db.execute("SELECT * FROM versions WHERE id=?", (target,)).fetchone()
|
|
200
|
+
if existing is not None:
|
|
201
|
+
result = {"version": version_info(existing), "changed": changed, "created": False}
|
|
202
|
+
prior = db.execute("SELECT * FROM version_derivations WHERE version=? AND base=?", (target, version_id)).fetchone()
|
|
203
|
+
if prior is not None:
|
|
204
|
+
result["derivation"] = derivation_info(prior)
|
|
205
|
+
return result
|
|
206
|
+
target = persist_version(db, spec, content)
|
|
207
|
+
receipt = (target, version_id, summary.strip(), now())
|
|
208
|
+
db.execute("INSERT INTO version_derivations(version,base,summary,created) VALUES (?,?,?,?)", receipt)
|
|
209
|
+
db.execute("INSERT INTO version_manifests(version,digest) VALUES (?,?)", (target, manifest_digest))
|
|
210
|
+
stored = db.execute("SELECT * FROM version_derivations WHERE version=?", (target,)).fetchone()
|
|
211
|
+
return {"version": version_info(version_row(db, target)), "changed": True, "created": True,
|
|
212
|
+
"derivation": derivation_info(stored)}
|