Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/PROJECT_SCRIPT_CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ For multi-step workflows such as `prepare`, `submit`, and `fetch`:

## Reference Implementation

- `canonical_answer_protocol/` is the current reference implementation of these conventions.
- `uncertainty_quantification_via_physics_semantics/` is the current reference implementation of these conventions.
36 changes: 19 additions & 17 deletions src/prkit/core/project_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path

_TOOLKIT_ENV_VAR = "PRKIT_TOOLKIT_ROOT"
_CANONICAL_ENV_VAR = "PRKIT_CANONICAL_ROOT"
_UQPS_ENV_VAR = "PRKIT_UQPS_ROOT"
_UQ_ENV_VAR = "PRKIT_UQ_ROOT"


Expand Down Expand Up @@ -69,36 +69,38 @@ def find_toolkit_root(anchor: str | PathLike[str] | Path | None = None) -> Path
)


def find_canonical_root(
def find_uqps_root(
anchor: str | PathLike[str] | Path | None = None,
) -> Path | None:
"""Return the canonical-answer-protocol repo root when present."""
"""Return the uqps (uncertainty-quantification-via-physics-semantics) repo root when present."""
env_root = _resolve_env_root(
_CANONICAL_ENV_VAR,
_UQPS_ENV_VAR,
marker_relpath=("scripts", "__init__.py"),
)
if env_root is not None:
return env_root

toolkit_root = find_toolkit_root(anchor)
if toolkit_root is not None:
sibling_root = toolkit_root.parent / "canonical_answer_protocol"
sibling_root = (
toolkit_root.parent / "uncertainty_quantification_via_physics_semantics"
)
if (sibling_root / "scripts").is_dir():
return sibling_root
nested_root = toolkit_root / "canonical_answer_protocol"
nested_root = toolkit_root / "uncertainty_quantification_via_physics_semantics"
if (nested_root / "scripts").is_dir():
return nested_root

for candidate in _iter_search_dirs(anchor):
if (
candidate.name == "canonical_answer_protocol"
candidate.name == "uncertainty_quantification_via_physics_semantics"
and (candidate / "scripts").is_dir()
):
return candidate

return _find_named_sibling(
anchor,
"canonical_answer_protocol",
"uncertainty_quantification_via_physics_semantics",
marker_relpath=("scripts", "__init__.py"),
)

Expand All @@ -114,8 +116,8 @@ def find_repo_root(
"""
if repo_name == "physical_reasoning_toolkit":
return find_toolkit_root(anchor)
if repo_name == "canonical_answer_protocol":
return find_canonical_root(anchor)
if repo_name == "uncertainty_quantification_via_physics_semantics":
return find_uqps_root(anchor)
if repo_name == "uncertainty_quantification_physical_reasoning":
return find_uq_root(anchor)
raise ValueError(f"Unsupported repo name: {repo_name}")
Expand Down Expand Up @@ -162,7 +164,7 @@ def project_dotenv_paths(

Precedence is:
1. toolkit root `.env`
2. `canonical_answer_protocol/.env`
2. `uncertainty_quantification_via_physics_semantics/.env`
3. `uncertainty_quantification_physical_reasoning/.env`

Later files win because they are loaded with `override=True`.
Expand All @@ -174,11 +176,11 @@ def project_dotenv_paths(
if repo_env.is_file():
paths.append(repo_env)

canonical_root = find_canonical_root(anchor)
if canonical_root is not None:
canonical_env = canonical_root / ".env"
if canonical_env.is_file() and canonical_env not in paths:
paths.append(canonical_env)
uqps_root = find_uqps_root(anchor)
if uqps_root is not None:
uqps_env = uqps_root / ".env"
if uqps_env.is_file() and uqps_env not in paths:
paths.append(uqps_env)

uq_root = find_uq_root(anchor)
if uq_root is not None:
Expand Down Expand Up @@ -233,10 +235,10 @@ def ensure_openai_api_key(

__all__ = [
"ensure_openai_api_key",
"find_canonical_root",
"find_repo_root",
"find_toolkit_root",
"find_uq_root",
"find_uqps_root",
"load_project_dotenv",
"project_dotenv_paths",
]
12 changes: 6 additions & 6 deletions src/prkit/evaluation/utils/sampling_backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from typing import Any

from prkit.core.project_env import (
find_canonical_root,
find_toolkit_root,
find_uq_root,
find_uqps_root,
)

DEFAULT_REPO_ROOT = find_toolkit_root(__file__) or Path(__file__).resolve().parents[4]
Expand All @@ -25,13 +25,13 @@
DEFAULT_INFERENCE_ROOT = (
DEFAULT_UQ_ROOT / "experiment_results" / "inference" / "response_with_answer_tag"
)
_default_canonical_root = find_canonical_root(__file__)
_default_uqps_root = find_uqps_root(__file__)
DEFAULT_CANONICAL_SAMPLING_ROOT = (
(_default_canonical_root / "baselines" / "sampling")
if _default_canonical_root is not None
(_default_uqps_root / "baselines" / "sampling")
if _default_uqps_root is not None
else (
DEFAULT_REPO_ROOT.parent
/ "canonical_answer_protocol"
/ "uncertainty_quantification_via_physics_semantics"
/ "baselines"
/ "sampling"
)
Expand Down Expand Up @@ -84,7 +84,7 @@ def parse_args() -> argparse.Namespace:
"--canonical-sampling-root",
type=Path,
default=None,
help="Override canonical_answer_protocol/baselines/sampling root.",
help="Override uncertainty_quantification_via_physics_semantics/baselines/sampling root.",
)
parser.add_argument(
"--missing-ids-dir",
Expand Down
Loading