"""Ontology — pure functions, no database.""" from __future__ import annotations import pytest from aiatlas.ontology import benchmarks as b from aiatlas.ontology.licenses import LICENSES, license_info, normalize_license from aiatlas.ontology.models import analyze_model_name, base_name, effort_config, family_hint, family_release_hint, is_official_org, variant_key from aiatlas.ontology.openness import derive_openness, normalize_openness, openness_dimensions from aiatlas.ontology.taxonomy import normalize_hardware_kind, normalize_modalities, normalize_org_kind, normalize_property, normalize_status # ---------------------------------------------------------------------------------------------- licences @pytest.mark.parametrize("raw", ["Apache 2.0", "apache-2.0", "Apache-2.0", "Apache License 2.0", "apache license, version 2.0", "APACHE2", "License: apache-2.0"]) def test_apache_variants_one_key(raw: str) -> None: assert normalize_license(raw) == "Apache-2.0" @pytest.mark.parametrize("raw,key", [ ("mit", "MIT"), ("Modified MIT", "MIT-Modified"), ("CC BY-NC 4.0", "CC-BY-NC-4.0"), ("cc-by-nc-4.0", "CC-BY-NC-4.0"), ("cc-by-4.0", "CC-BY-4.0"), ("llama3", "Llama-3-Community"), ("llama3.1", "Llama-3.1-Community"), ("llama3.2", "Llama-3.2-Community"), ("Llama 4 Community License", "Llama-4-Community"), ("gemma", "Gemma-Terms"), ("openrail++", "OpenRAIL++-M"), ("bigscience-bloom-rail-1.0", "BigScience-BLOOM-RAIL-1.0"), ("other", "Other"), ("apple-amlr", "Apple-AMLR"), ("bsd-3-clause", "BSD-3-Clause"), ("proprietary", "Proprietary"), ("GPLv3", "GPL-3.0"), ]) def test_license_table(raw: str, key: str) -> None: assert normalize_license(raw) == key assert key in LICENSES def test_unknown_license_is_none_not_guessed() -> None: assert normalize_license("weird-license-xyz") is None assert normalize_license("") is None and normalize_license(None) is None assert license_info("weird") is None # ---------------------------------------------------------------------------------------------- openness def test_openness_derivation() -> None: llama = openness_dimensions(weights_available=True, license_key="Llama-3.1-Community") assert derive_openness(llama, license_key="Llama-3.1-Community") == "restricted-weights" apache = openness_dimensions(weights_available=True, license_key="Apache-2.0") assert derive_openness(apache, license_key="Apache-2.0") == "open-weights" assert derive_openness({**apache, "source_code_available": True}, license_key="Apache-2.0") == "open-source" prop = openness_dimensions(weights_available=None, license_key="Proprietary") assert prop["weights_available"] is False and derive_openness(prop, license_key="Proprietary") == "proprietary" assert derive_openness(openness_dimensions(weights_available=None), license_key=None) == "unknown" nc = openness_dimensions(weights_available=True, license_key="CC-BY-NC-4.0") assert nc["commercial_use_allowed"] is False and derive_openness(nc, license_key="CC-BY-NC-4.0") == "restricted-weights" @pytest.mark.parametrize("raw,canon", [("open-weights", "open-weights"), ("restricted", "restricted-weights"), ("gated", "restricted-weights"), ("closed", "proprietary"), ("Open Source", "open-source"), ("", "unknown"), ("banana", None)]) def test_normalize_openness(raw: str, canon: str | None) -> None: assert normalize_openness(raw) == canon # ---------------------------------------------------------------------------------------------- taxonomy def test_modalities_and_status_and_kinds() -> None: assert normalize_modalities(["Text", "text", "pdf", "vision"]) == ["document", "image", "text"] assert normalize_modalities("text, image and audio") == ["audio", "image", "text"] assert normalize_status("limited-availability") == "limited-availability" and normalize_status("Available") == "active" assert normalize_status("archived") == "archived" and normalize_status("sunset") == "deprecated" and normalize_status("shutdown") == "retired" assert normalize_hardware_kind("computer") == "system" and normalize_hardware_kind("soc") == "soc" and normalize_hardware_kind("GPU") == "gpu" assert normalize_org_kind("startup") == "company" and normalize_org_kind("research institute") == "lab" and normalize_org_kind("organization") is None def test_normalize_property_keeps_unknown_values() -> None: value, raw, maps = normalize_property("model", "license", "Apache 2.0") assert value == "Apache-2.0" and raw == "Apache 2.0" and ("license", "Apache 2.0", "Apache-2.0") in maps value, raw, maps = normalize_property("model", "license", "totally-custom") assert value == "totally-custom" and raw is None and maps == [("license", "totally-custom", None)] value, raw, maps = normalize_property("model", "modalities", ["Text", "smell", "pdf"]) assert value == ["document", "smell", "text"] and raw == "Text, smell, pdf" # unknown modality kept, never dropped assert ("modality", "smell", None) in maps value, raw, _ = normalize_property("model", "modalities", ["text"]) assert value == ["text"] and raw is None assert normalize_property("hardware", "kind", "computer")[0] == "system" assert normalize_property("framework", "kind", "framework")[0] == "training-framework" assert normalize_property("model", "kind", "whatever")[0] == "whatever" # `kind` is only a taxonomy for hardware/frameworks assert normalize_property("model", "parameter_count", 7_000_000_000) == (7_000_000_000, None, []) # ---------------------------------------------------------------------------------------------- model names NAMES = { # name → (is_artifact, is_effort_variant, base_key, family_release_hint) "Qwen3.6-35B-A3B": (False, False, "qwen3-6-35b-a3b", "Qwen3.6"), "unsloth/Qwen3.6-35B-A3B-GGUF": (True, False, "qwen3-6-35b-a3b", "Qwen3.6"), "Qwen3.6-35B-A3B-FP8": (True, False, "qwen3-6-35b-a3b", "Qwen3.6"), "mlx-community/Kimi-K2.5": (True, False, "kimi-k2-5", "Kimi"), "zai-org/GLM-5-FP8": (True, False, "glm-5", "GLM5"), "amd/Llama-3.3-70B-Instruct-MXFP4": (True, False, "llama-3-3-70b-instruct", "Llama 3.3"), "bartowski/Qwen3.8-27B-GGUF": (True, False, "qwen3-8-27b", "Qwen3.8"), "meta-llama/Llama-4-Maverick-17B-128E-Instruct": (False, False, "llama-4-maverick-17b-128e-instruct", "Llama 4"), "claude-fable-5-1-xhigh": (False, True, "claude-fable-5-1", "Claude"), "gpt-6-astra-high": (False, True, "gpt-6-astra", "GPT 6"), "deepseek-v4-pro-0424-non-reasoning": (False, True, "deepseek-v4-pro-0424", "DeepSeek"), "gpt-5-4-mini-medium": (False, True, "gpt-5-4-mini", "GPT 5.4"), "Qwen3 Max Thinking": (False, True, "qwen3-max", "Qwen3"), "Kimi K2 Thinking": (False, False, "kimi-k2-thinking", "Kimi"), "Qwen3-Max": (False, False, "qwen3-max", "Qwen3"), # "max" is a tier, not an effort "GPT-5.1-Codex-Max": (False, False, "gpt-5-1-codex-max", "GPT 5.1"), "Grok 4.1 Fast": (False, False, "grok-4-1-fast", "Grok 4.1"), "gemini-2-0-flash-thinking-exp-1219": (False, False, "gemini-2-0-flash-thinking-exp-1219", "Gemini 2.0"), "Llama 3.1 70B Instruct": (False, False, "llama-3-1-70b-instruct", "Llama 3.1"), "Qwen 38B": (False, False, "qwen-38b", "Qwen"), "Qwen3-235B-A22B": (False, False, "qwen3-235b-a22b", "Qwen3"), "deepseek-ai/DeepSeek-V4-Flash-0731": (False, False, "deepseek-v4-flash-0731", "DeepSeek"), } @pytest.mark.parametrize("name", sorted(NAMES)) def test_analyze_model_name(name: str) -> None: is_artifact, is_variant, base, fam = NAMES[name] a = analyze_model_name(name) assert a.is_artifact is is_artifact, (name, a) assert a.is_effort_variant is is_variant, (name, a) assert a.base_key == base, (name, a.base_key) assert family_release_hint(name) == fam, (name, family_release_hint(name)) def test_variant_key_groups_artifacts_with_their_model() -> None: assert variant_key("Qwen3.6-35B-A3B") == variant_key("unsloth/Qwen3.6-35B-A3B-GGUF") == variant_key("Qwen3.6 35B A3B FP8") == "qwen3-6-35b-a3b" assert variant_key("Qwen3-8B") != variant_key("Qwen 38B") assert variant_key("Llama 3.1 70B Instruct") == variant_key("meta-llama/Llama-3.1-70B-Instruct") == "llama-3-1-70b" def test_effort_helpers() -> None: assert base_name("gpt-5-4-mini-medium") == "gpt-5-4-mini" and base_name("Qwen3 Max Thinking") == "Qwen3 Max" and base_name("Qwen3-Max") == "Qwen3-Max" cfg = effort_config("gpt-5-4-mini-medium", {"aa_slug": "gpt-5-4-mini-medium", "evaluator": "AA"}) assert cfg["reasoning_effort"] == "medium" and cfg["aa_variant_slug"] == "gpt-5-4-mini-medium" and cfg["evaluator"] == "AA" assert effort_config("Qwen3-Max", {"x": 1}) == {"x": 1} assert analyze_model_name("claude-fable-5-1-xhigh").parameter_count is None assert analyze_model_name("Qwen3.6-35B-A3B").active_parameter_count == 3_000_000_000 assert family_hint("o3-mini") == "OpenAI o-series" and family_hint("random-thing") is None assert is_official_org("meta-llama", "Llama 4 Maverick") and not is_official_org("unsloth", "Llama 4 Maverick") # ---------------------------------------------------------------------------------------------- benchmarks def test_comparability_trio() -> None: a = {"variant": "Verified", "system": "mini-SWE-agent", "reasoning_effort": "high"} same = {"variant": "Verified", "system": "mini-SWE-agent", "reasoning_effort": "high"} cond = {"variant": "Verified", "system": "mini-SWE-agent", "reasoning_effort": "low"} task = {"variant": "Lite", "system": "mini-SWE-agent", "reasoning_effort": "high"} assert b.comparability(a, same, "resolved", "resolved")[0] == b.COMPARABLE assert b.comparability(a, cond, "resolved", "resolved")[0] == b.PARTIAL assert b.comparability(a, task, "resolved", "resolved")[0] == b.NOT_COMPARABLE assert b.comparability(a, same, "resolved", "pass@1")[0] == b.NOT_COMPARABLE assert b.comparability(a, same, same_benchmark=False)[0] == b.NOT_COMPARABLE # config_key ignores condition and bookkeeping keys, keeps task keys + metric assert b.config_key(a, "resolved") == b.config_key(cond, "resolved") == b.config_key({**a, "aa_slug": "x", "date": "2026"}, "resolved") assert b.config_key(a, "resolved") != b.config_key(task, "resolved") != b.config_key(a, "pass@1") def test_metric_bounds_and_trust() -> None: assert b.metric_bounds("accuracy") == (0, 100) and b.metric_bounds("pass rate (2 attempts)") == (0, 100) and b.metric_bounds("category:Reasoning") == (0, 100) assert b.metric_bounds("elo") == (0, None) and b.metric_bounds("score") == (None, None) and b.metric_bounds("weird", "%") == (0, 100) assert b.normalize_metric("Percent Resolved") == "resolved" and b.normalize_metric("Elo / Bradley–Terry score") == "elo" assert b.trust_level("swebench.com", {"checked_by_swebench": True}) == "official-benchmark" assert b.trust_level("swebench.com", {"checked_by_swebench": False}) == "community" assert b.trust_level("artificialanalysis.ai") == "independent-evaluator" and b.trust_level("docs.claude.com") == "official-model-card" assert b.trust_level(None, extractor="llm") == "unverified" assert b.run_group_from_config({"release": "2026-06-25"}) == "2026-06-25" and b.run_group_from_config({"index_version": "4.3"}) == "4.3" assert b.variant_from_config({"board": "Multilingual"}) == "Multilingual" and b.family_of("swe-bench-verified") == ("swe-bench", "Verified")