Skip to content

symphony_dt.governance

symphony_dt.governance

Governance: manifests, fingerprints, pre-registration, provenance, cards, credibility plans and appraisal aids.

DeviationRecord dataclass

An explicit, signed record of a change to a frozen specification.

Validation: TESTED.

FrozenSpec dataclass

A specification hash with the time it was frozen.

Validation: TESTED.

to_dict

to_dict() -> dict[str, Any]

Return a JSON-serialisable form.

Validation: TESTED.

ScoringSpec

Bases: BaseModel

Every choice the scoring makes, fixed before any target is scored.

ScoringSpec.default() reproduces the SYMPHONY v2 code of record: anchor 2.0 years, nine horizon bins, 30 residuals per bin, windows next, 1y, 2y and all, events of +5 UPDRS-III and -2 MoCA, B = 1000 bootstrap replicates and no cell from fewer than 10 participants.

Validation: TESTED.

default classmethod

default() -> ScoringSpec

Return the code-of-record specification.

Validation: TESTED.

canonical

canonical() -> str

Return the canonical JSON used for hashing: sorted keys, infinities as 1e300.

Validation: TESTED.

sha256

sha256() -> str

Return the sha256 of the canonical JSON.

Validation: TESTED.

CredibilityEvidence dataclass

One piece of evidence for a credibility factor, with where it came from.

Validation: TESTED.

CredibilityFactor dataclass

One credibility factor of a plan: its goal at the plan's model risk and the evidence it needs.

goal holds the requirements at the plan's risk level and every level below it. needed maps each evidence key to what is needed. evidence holds what manifests or the user supplied.

Validation: TESTED.

status

status(key: str) -> str

Return where the evidence for key stands: found in manifest, supplied by the user, or to be supplied.

Validation: TESTED.

CredibilityPlan dataclass

A credibility plan: question, context of use, model risk, and goals and evidence per factor.

table has one row per evidence item, with its factor, the risk level from which it is needed, its status, the value found and its source. No column says that a goal is met.

Validation: TESTED.

to_dict

to_dict() -> dict[str, Any]

Return the plan as a JSON-serialisable dict.

Validation: TESTED.

to_markdown

to_markdown() -> str

Return the plan as a Markdown document with every factor, its goal and its evidence.

Validation: TESTED.

RunManifest dataclass

The record of one fit, forecast, evaluation or simulation.

Validation: TESTED.

create classmethod

create(
    kind: str,
    *,
    started: float | None = None,
    **fields: Any,
) -> RunManifest

Create a manifest stamped with the package version, the time and the environment.

Validation: TESTED.

to_dict

to_dict() -> dict[str, Any]

Return the manifest as a JSON-serialisable dict.

Validation: TESTED.

sha256

sha256() -> str

Return the digest of the manifest content.

Validation: TESTED.

write

write(path: str | Path) -> Path

Write the manifest as indented JSON and return the path.

Validation: TESTED.

read classmethod

read(path: str | Path) -> RunManifest

Read a manifest written by write.

Validation: TESTED.

to_html

to_html() -> str

Return a self-contained HTML page describing the run.

Validation: TESTED.

ProbastAppraisal dataclass

A PROBAST+AI appraisal: answers, per-domain judgements and the overall judgements.

table has one row per domain. It holds the answer counts, the judgement the rule gives, the judgement kept after any override with its reason, and the applicability concern. overall is the overall risk of bias for the evaluation part, or concern for quality for the development part.

Validation: TESTED.

judgement_label property

judgement_label: str

Return "risk of bias" for the evaluation part and "concern for quality" for development.

Validation: TESTED.

to_markdown

to_markdown() -> str

Return a Markdown appraisal with every prompt, its answer and the domain judgements.

Unanswered prompts are marked TO DO.

Validation: TESTED.

ProvenanceDocument dataclass

A PROV-JSON document with the sdt namespace for symphony-dt identifiers.

Validation: TESTED.

entity

entity(
    name: str,
    *,
    sha256: str,
    kind: str = "file",
    **attributes: Any,
) -> str

Add an entity identified by its digest and return its PROV id.

Validation: TESTED.

activity

activity(
    name: str,
    *,
    started: str | None = None,
    ended: str | None = None,
    **attributes: Any,
) -> str

Add an activity and return its PROV id.

Validation: TESTED.

agent

agent(
    name: str,
    *,
    kind: str = "prov:SoftwareAgent",
    **attributes: Any,
) -> str

Add an agent and return its PROV id.

Validation: TESTED.

use

use(activity: str, entity: str) -> None

Record that activity used entity.

Validation: TESTED.

generate

generate(entity: str, activity: str) -> None

Record that entity was generated by activity.

Validation: TESTED.

associate

associate(activity: str, agent: str) -> None

Record that activity was associated with agent.

Validation: TESTED.

for_run classmethod

for_run(
    activity: str,
    inputs: dict[str, str],
    outputs: dict[str, str],
) -> ProvenanceDocument

Build a document for one run: inputs and outputs given as name to sha256.

Validation: TESTED.

to_dict

to_dict() -> dict[str, Any]

Return the PROV-JSON structure.

Validation: TESTED.

write

write(path: str | Path) -> Path

Write the document as JSON and return the path.

Validation: TESTED.

ReproduceReport dataclass

The outcome of reproduce: per-output digest comparison.

Validation: TESTED.

reproduced property

reproduced: bool

True when every recorded output digest was reproduced.

freeze_spec

freeze_spec(
    spec: ScoringSpec, path: str | Path | None = None
) -> FrozenSpec

Freeze a specification: hash it and, when path is given, write spec and hash to disk.

The file holds the canonical specification and its sha256, so a reader can check the freeze without the package.

Validation: TESTED.

load_frozen_spec

load_frozen_spec(
    path: str | Path,
) -> tuple[ScoringSpec, FrozenSpec]

Read a frozen specification file and check its hash.

Validation: TESTED.

require_frozen

require_frozen(
    spec: ScoringSpec,
    frozen: FrozenSpec | None,
    deviation: DeviationRecord | None = None,
) -> dict[str, Any]

Check spec against its freeze and return the record that travels with the scores.

Raises UnfrozenSpecificationError when frozen is None, or when the hashes differ and no deviation record is given.

Validation: TESTED.

data_card_markdown

data_card_markdown(
    dataset: TwinDataset,
    *,
    title: str = "Data card",
    min_cell: int = 10,
    source: str = "",
) -> str

Return a data card: aggregate counts, envelope warnings and the dataset fingerprint.

Any count of participants below min_cell is shown as <min_cell.

Validation: TESTED.

model_card_markdown

model_card_markdown(name: str = 'pd_v2') -> str

Return the model card of a registered model, with its verified digests appended.

Validation: TESTED.

credibility_plan

credibility_plan(
    question: str,
    context_of_use: str,
    *,
    model_influence: str,
    decision_consequence: str,
    manifests: Sequence[
        RunManifest | Mapping[str, Any] | str | Path
    ] = (),
    supplied: Mapping[str, str] | None = None,
    title: str = "Model credibility plan",
) -> CredibilityPlan

Build a credibility plan in the style of ASME V&V 40.

Model risk comes from model_risk(model_influence, decision_consequence). Each factor's goal holds the requirements up to that risk. Evidence is filled from the given manifests (objects, dicts or JSON paths) where they record it, each citing its manifest. supplied maps evidence keys to the user's own evidence; an unknown key raises KeyError. The plan states goals and lists evidence; it never marks a goal as met.

Validation: TESTED.

model_risk

model_risk(influence: str, consequence: str) -> str

Return the model risk for a model influence and a decision consequence.

Both take low, medium or high; anything else raises ValueError. The mapping is MODEL_RISK_MATRIX, an illustrative matrix, since ASME V&V 40 leaves the matrix to the user.

Validation: TESTED.

environment

environment() -> dict[str, Any]

Return the computing environment: Python, platform, package versions and CmdStan.

Validation: TESTED.

fingerprint

fingerprint(obj: Any) -> str

Return the sha256 of a canonical JSON serialisation of obj.

Dictionaries are sorted by key and numpy values are converted, so equal content gives an equal digest. Objects with a fingerprint() method, such as TwinDataset, use it.

Validation: TESTED.

probast_appraisal

probast_appraisal(
    answers: Mapping[str, str],
    *,
    part: str = "evaluation",
    applicability: Mapping[str, str] | None = None,
    overrides: Mapping[str, tuple[str, str]] | None = None,
    overall_override: tuple[str, str] | None = None,
    title: str = "PROBAST+AI appraisal",
) -> ProbastAppraisal

Judge each domain and the study overall from signalling answers keyed by item id.

Answers are yes, probably yes, probably no, no, no information or not applicable, or their abbreviations Y, PY, PN, N, NI and NA. Unknown ids and answers raise, so a typo cannot hide an item. applicability rates participants, predictors and outcome as low, high or unclear; a domain left out counts as unclear. overrides maps a domain to a (judgement, reason) pair, and overall_override does the same for the overall judgement. See the module docstring for the rules.

Validation: TESTED.

probast_items

probast_items(
    part: str = "evaluation",
) -> list[dict[str, str]]

Return the paraphrased signalling prompts as dicts with id, domain, heading and prompt.

part is "development" (concern for quality) or "evaluation" (risk of bias). The first three domains share their prompts; the analysis prompts differ by part.

Validation: TESTED.

tripod_ai_items

tripod_ai_items() -> list[dict[str, str]]

Return the checklist prompts as dicts with key, heading and prompt.

Validation: TESTED.

tripod_ai_report

tripod_ai_report(
    answers: Mapping[str, str],
    *,
    title: str = "TRIPOD+AI checklist",
) -> str

Return a Markdown checklist with the user's answers; unanswered prompts are marked TO DO.

Unknown keys in answers raise KeyError, so a typo cannot hide an item.

Validation: TESTED.