Files
planet/backend/app/services/compute_history.py
T
rayd1o 5bfc790dec
ci / backend (push) Has been cancelled
ci / frontend (push) Has been cancelled
release / images (push) Has been cancelled
ci / delivery (push) Has been cancelled
release: bump version to 0.75.0
2026-09-23 21:20:12 +08:00

156 lines
6.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Versioned, source-backed annual observations for compute comparisons."""
from copy import deepcopy
from app.services.compute_catalog import (
CATALOG,
DEFAULT_PARTICIPANTS,
PARTICIPANTS,
participant_members,
)
HISTORY_VERSION = "compute-history-2026-09-22"
HISTORY_YEARS = tuple(range(2020, 2027))
REPORTS = {
"caict-2021": {
"title": "中国算力发展指数白皮书(2021)",
"url": "https://www.caict.ac.cn/kxyj/qwfb/bps/202109/P020210918521091309950.pdf",
"publisher": "中国信息通信研究院",
"report_year": 2021,
"published_at": None,
"locator": "正文 11 页图 4(2020 年全球份额)",
},
"caict-2022": {
"title": "中国算力发展指数白皮书(2022)",
"url": "https://www.caict.ac.cn/kxyj/qwfb/bps/202211/P020221105727522653499.pdf",
"publisher": "中国信息通信研究院",
"report_year": 2022,
"published_at": None,
"locator": "正文 13 页图 5(2021 年全球份额)",
},
"caict-2023": {
"title": "中国算力发展指数白皮书(2023)",
"url": "https://www.caict.ac.cn/kxyj/qwfb/bps/202309/P020240326630458153765.pdf",
"publisher": "中国信息通信研究院",
"report_year": 2023,
"published_at": None,
"locator": "正文 13 页图 5(2022 年全球份额);16 页(中国总规模)",
},
"caict-2024": {
"title": "先进计算暨算力发展指数蓝皮书(2024年)",
"url": "https://www.caict.ac.cn/kxyj/qwfb/bps/202501/P020250117503621662777.pdf",
"publisher": "中国信息通信研究院",
"report_year": 2024,
"published_at": None,
"locator": "正文 10 页图 3(2023 年全球份额);12 页(中国总规模)",
},
"innovation-2026": {
"title": "全球人工智能创新指数报告 2026:科技日报报道",
"url": "https://finance.sina.com.cn/tech/roll/2026-07-17/doc-iniickaz8224252.shtml",
"publisher": "科技日报(新浪转载)",
"published_at": "2026-07-17",
"publication_year": 2026,
"locator": "2023–2025 年美国减中国的指数分差",
},
}
GLOBAL_SHARES = {
year: {"US": us, "CN": cn, "JP": jp}
for year, (us, cn, jp) in {
2020: (36, 31, 6), 2021: (34, 33, 5),
2022: (34, 33, 4), 2023: (41, 31, 4),
}.items()
}
ABSOLUTE_COMPUTE = {2022: {"CN": 302}, 2023: {"CN": 435}}
GAPS = {2023: 22.02, 2024: 19.96, 2025: 17.95}
def _observations(mode: str, year: int) -> dict[str, float | int]:
return (GLOBAL_SHARES if mode in {"global_share", "bilateral_share"} else ABSOLUTE_COMPUTE).get(
year, {}
)
def _participant_value(
members: tuple[str, ...], observations: dict[str, float | int], mode: str
) -> tuple[float | int | None, dict]:
covered = [member for member in members if member in observations]
missing = [member for member in members if member not in observations]
coverage = {
"status": "complete" if not missing else "incomplete",
"required_members": list(members),
"covered_members": covered,
"missing_members": missing,
}
if missing:
return None, coverage
if mode == "bilateral_share":
if not set(members).issubset({"CN", "US"}) or not {"CN", "US"}.issubset(observations):
coverage.update(
{
"status": "incompatible",
"reason": "bilateral_share_requires_CN_and_US_observations",
}
)
return None, coverage
return (
round(
sum(observations[member] for member in members)
/ (observations["US"] + observations["CN"]) * 100,
2,
),
coverage,
)
return sum(observations[member] for member in members), coverage
def compute_history(countries: list[str], mode: str = "global_share") -> dict:
"""Aggregate only fully covered, same-year compatible observations."""
members_by_participant = participant_members(countries)
rows = []
for year in HISTORY_YEARS:
observations = _observations(mode, year)
values, coverage = {}, {}
for code, members in members_by_participant.items():
values[code], coverage[code] = _participant_value(members, observations, mode)
evidence_id = f"caict-{year + 1}" if observations else None
rows.append(
{"year": year, "values": values, "coverage": coverage, "evidence_id": evidence_id}
)
selected_members = {member for members in members_by_participant.values() for member in members}
has_innovation_scope = {"CN", "US"}.issubset(selected_members)
return {
"version": HISTORY_VERSION,
"provenance": "reviewed_official_reports",
"reviewed_at": "2026-09-22",
"time_basis": "retrospective",
"years": HISTORY_YEARS,
"mode": mode,
"unit": "EFlop/s (FP32)" if mode == "absolute" else "%",
"denominator": {"global_share": "global", "bilateral_share": "US+CN", "absolute": None}[
mode
],
"catalog": deepcopy(CATALOG),
"default_participants": list(DEFAULT_PARTICIPANTS),
"countries": [deepcopy(PARTICIPANTS[code]) for code in countries],
"compute": rows,
"innovation": [
{
"year": year,
"value": GAPS.get(year) if has_innovation_scope else None,
"evidence_id": "innovation-2026" if year in GAPS and has_innovation_scope else None,
}
for year in HISTORY_YEARS
],
"evidence": deepcopy(REPORTS),
"innovation_scope": ["US", "CN"],
"limitations": [
"公开设施样本不代表全国总算力;FP64、FP16 与 FP32 不可直接相加。",
"区域值只在全部成员有同年、同指标、可比较观测时汇总;缺失成员时返回 null。",
"全球份额不从中美或其他局部成员反推剩余地区。",
"年度资料来自信通院官方报告,观测年与报告年份分列;跨年方法可比性仍需核验。",
"创新分差为美国减中国;只有分差,不反推单国得分,不证明算力与创新的因果关系。",
],
}