topos.evaluation.characteristic_morphism

Characteristic Morphism χ_S : P → Ω

This module implements the characteristic morphism of the program topos. Per the math spec §3, for every program P E and every subprogram S P there exists a unique natural transformation

χ_S : P → Ω

mapping each structural component to an element of Ω. This file contains the map; the codomain Ω itself lives in topos.core.omega.

Categorical / Pythonic correspondence:

Math                   Python
------------------     -----------------------------------------
Ω                      Omega                       (topos.core.omega)
elements of Ω          EvaluationValue              (topos.core.omega)
χ_S : P → Ω            CharacteristicMorphism       (this module)
image of χ_S(P)        ClassificationResult         (this module)

The characteristic morphism:

  1. Builds every available Representation (AST + CFG + ModuleDependencyGraph + CPG) for the morphism.

  2. Groups them by generator (each Representation declares its dimension ∈ {“simple”, “composable”, “secure”}).

  3. Runs the matching policy translator Φᵢ on the collected metrics (simple → Φ_SIMPLE, etc.).

  4. Combines the three Boolean truth values via topos.core.omega.verdict_from_generators() into the final Ω element.

Priority is recorded on results and steers agent guidance; it does not change per-metric pass/fail thresholds inside each Φᵢ.

class topos.evaluation.characteristic_morphism.ClassificationResult(is_parseable, dimensions=<factory>, scores=<factory>, lattice_element=EvaluationValue.SLOP, priority=Priority.SECURE, raw_metrics=<factory>, interpretation=<factory>)[source]

Bases: object

The image of one program morphism under χ_S : P → Ω.

is_parseable

Whether the code parsed successfully.

Type:

bool

dimensions

Per-generator value in Ω: the singleton generator (SIMPLE/COMPOSABLE/SECURE) when satisfied, SLOP otherwise.

Type:

dict[str, topos.core.omega.EvaluationValue]

scores

Per-generator normalized quality score in [0.0, 1.0].

Type:

dict[str, float]

lattice_element

Overall Ω element — the join of the satisfied generators, encoded via verdict_from_generators.

Type:

topos.core.omega.EvaluationValue

priority

Generator emphasis label (metadata / guidance).

Type:

topos.evaluation.policies.base.Priority

raw_metrics

All raw metric floats, namespaced by representation.

Type:

dict[str, float]

interpretation

Per-metric interpretation strings.

Type:

dict[str, str]

is_parseable
dimensions
scores
lattice_element = 0
priority = 'secure'
raw_metrics
interpretation
summary()[source]

The overall Ω element χ_S(P).

class topos.evaluation.characteristic_morphism.CharacteristicMorphism(omega=<factory>)[source]

Bases: object

χ_S : P → Ω — the characteristic morphism of the program topos.

For every program morphism P (and the canonical subprogram S = P itself, in the absence of a finer subobject) this object computes the natural-transformation image χ_S(P) as an EvaluationValue in Ω.

Each generator gᵢ is fed by the Representation theory says is the correct lens for that quality:

SIMPLE ← CFG cyclomatic complexity COMPOSABLE ← ModuleDependencyGraph coupling / instability SECURE ← Code Property Graph taint / danger probes

omega

The subobject classifier Ω (the value Heyting algebra).

Type:

topos.core.omega.Omega

omega
classify(morphism)[source]

Return classify_detailed(...).summary() — the overall Ω element.

classify_detailed(morphism, representations=None, priority=Priority.SECURE)[source]

Compute χ_S : P → Ω in full detail.

An ASTRepresentation is always built from the morphism (it carries ast.entropy into the SIMPLE generator). Any additional representations (CFG, ModuleDependencyGraph, PDG, CPG) are grouped by their dimension and scored independently.

Parse failures collapse to ⊥ = SLOP.

combine(*values)[source]

Combine multiple Ω values via meet (∧).

combine_dimensions(results, thresholds=None)[source]

Pointwise multi-file meet ⋀_f χ_S(f).

A generator is satisfied across the codebase iff it is satisfied for every file (minimum score across files ≥ its calibrated threshold). Parse failures inject a zero score on the SIMPLE generator (since the program failed even to compile, no other generator is reachable).