arkhai-compute 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ """Compute-family market vocabulary shared by every compute domain."""
2
+
3
+ from arkhai_compute.capability_schema import (
4
+ COMPUTE_CAPABILITY_SCHEMA,
5
+ DIMENSION_KEYS,
6
+ DISK_GB_DIMENSION,
7
+ GPU_COUNT_DIMENSION,
8
+ GPU_MODEL_ATTRIBUTE,
9
+ RAM_GB_DIMENSION,
10
+ VCPU_COUNT_DIMENSION,
11
+ )
12
+
13
+ __all__ = [
14
+ "COMPUTE_CAPABILITY_SCHEMA",
15
+ "DIMENSION_KEYS",
16
+ "DISK_GB_DIMENSION",
17
+ "GPU_COUNT_DIMENSION",
18
+ "GPU_MODEL_ATTRIBUTE",
19
+ "RAM_GB_DIMENSION",
20
+ "VCPU_COUNT_DIMENSION",
21
+ ]
@@ -0,0 +1,54 @@
1
+ """The compute family's capability-shape vocabulary.
2
+
3
+ Every compute domain states and reads capacity in these families and fields, so
4
+ a VM listing and a bare-metal listing with the same hardware flatten to the same
5
+ published fields, claim dimensions, and site declaration keys. Translation into
6
+ a specific provisioning playbook belongs to that provider's requirement
7
+ delegate, not here. See openspec/specs/market-composition/spec.md.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from market_capability_shape import CapabilitySchema, FieldKind, ShapeField
13
+
14
+ GPU_COUNT_DIMENSION = "gpu_count"
15
+ VCPU_COUNT_DIMENSION = "vcpu_count"
16
+ RAM_GB_DIMENSION = "ram_gb"
17
+ DISK_GB_DIMENSION = "disk_gb"
18
+
19
+ DIMENSION_KEYS: tuple[str, ...] = (
20
+ GPU_COUNT_DIMENSION,
21
+ VCPU_COUNT_DIMENSION,
22
+ RAM_GB_DIMENSION,
23
+ DISK_GB_DIMENSION,
24
+ )
25
+
26
+ GPU_MODEL_ATTRIBUTE = "gpu_model"
27
+
28
+ # The flat names are the published listing fields, the capacity-claim
29
+ # dimensions, and the site's declared capacity keys, so they are the existing
30
+ # wire names rather than family-prefixed ones: ``memory.gib`` flattens to
31
+ # ``ram_gb`` and ``storage.gib`` to ``disk_gb``. Both are GiB. No family is
32
+ # required: a family a shape omits states nothing about it, so a machine without
33
+ # GPUs states no ``gpu`` family. ``gpu.count`` and ``gpu.model`` are required
34
+ # together, because a GPU commitment always names how many and which model: a
35
+ # shape states both or neither.
36
+ COMPUTE_CAPABILITY_SCHEMA = CapabilitySchema(
37
+ fields=(
38
+ ShapeField("gpu", "count", FieldKind.QUANTITY, GPU_COUNT_DIMENSION, required=True),
39
+ ShapeField("gpu", "model", FieldKind.ATTRIBUTE, GPU_MODEL_ATTRIBUTE, required=True),
40
+ ShapeField("cpu", "count", FieldKind.QUANTITY, VCPU_COUNT_DIMENSION),
41
+ ShapeField("memory", "gib", FieldKind.QUANTITY, RAM_GB_DIMENSION),
42
+ ShapeField("storage", "gib", FieldKind.QUANTITY, DISK_GB_DIMENSION),
43
+ )
44
+ )
45
+
46
+ __all__ = [
47
+ "COMPUTE_CAPABILITY_SCHEMA",
48
+ "DIMENSION_KEYS",
49
+ "DISK_GB_DIMENSION",
50
+ "GPU_COUNT_DIMENSION",
51
+ "GPU_MODEL_ATTRIBUTE",
52
+ "RAM_GB_DIMENSION",
53
+ "VCPU_COUNT_DIMENSION",
54
+ ]
@@ -0,0 +1,146 @@
1
+ """Interpret site ends from retained compute command and Agreement evidence.
2
+
3
+ The caller supplies journal facts; this module owns no storage, authority client
4
+ or delivery effects. A site cause alone never establishes financial entitlement.
5
+ """
6
+
7
+ from collections.abc import Callable, Iterable, Iterator, Mapping
8
+ from dataclasses import dataclass
9
+ from typing import Any, Protocol, TypeVar
10
+
11
+
12
+ class SiteEnd(Protocol):
13
+ event_id: str
14
+ effective_at: int
15
+ reason: str | None
16
+ caller: Any
17
+ cause: str
18
+ source_state: str
19
+ deadline_phase: str | None
20
+ claimed_deadline: int | None
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class CommandEnd:
25
+ command_ref: str
26
+ kind: str
27
+ at: int
28
+ source_ref: str
29
+ classification: str | None
30
+ evidence_refs: list[str]
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class SiteClassification:
35
+ kind: str | None
36
+ evidence_refs: list[str]
37
+ controlling_source_ref: str | None = None
38
+
39
+
40
+ class EndRequest(Protocol):
41
+ source_ref: str
42
+ source: str
43
+ ended_at: int
44
+
45
+
46
+ class PhysicalCommand(Protocol):
47
+ intent_ref: str
48
+ kind: str
49
+ payload: dict
50
+
51
+
52
+ class ClassifiedEvidence(Protocol):
53
+ kind: str
54
+ evidence_refs: list[str]
55
+
56
+
57
+ RequestT = TypeVar("RequestT", bound=EndRequest)
58
+ ActorT = TypeVar("ActorT")
59
+
60
+
61
+ def site_classification(
62
+ event: SiteEnd, *, seller: Any, term_end: int, available: bool,
63
+ intents: Iterable[PhysicalCommand], requests: Iterable[EndRequest],
64
+ classifications: Mapping[str, ClassifiedEvidence | None], termination_ref: str,
65
+ ) -> SiteClassification:
66
+ """Correlate supplied immutable journal facts without owning their storage."""
67
+ requests = tuple(requests)
68
+ commands = []
69
+ for intent in intents:
70
+ if intent.kind not in {"terminate", "truncate"}:
71
+ continue
72
+ for request in requests:
73
+ classification = classifications.get(request.source_ref)
74
+ if request.ended_at == intent.payload["at"] and classification is not None:
75
+ commands.append(CommandEnd(
76
+ intent.intent_ref, intent.kind, intent.payload["at"], request.source_ref,
77
+ classification.kind, classification.evidence_refs,
78
+ ))
79
+ return classify_site_end(
80
+ event, seller=seller, term_end=term_end, available=available,
81
+ commands=commands, termination_ref=termination_ref,
82
+ )
83
+
84
+
85
+ def resolve_site_corrections(
86
+ requests: Iterable[RequestT], *, classifications: Mapping[str, ClassifiedEvidence | None],
87
+ report_for: Callable[[str], SiteEnd], classify: Callable[[SiteEnd], SiteClassification],
88
+ ) -> Iterator[tuple[RequestT, SiteClassification]]:
89
+ """Select resolvable pending site statements; callers own codec and atomic writes."""
90
+ for request in requests:
91
+ if request.source != "lease_ended" or classifications.get(request.source_ref) is not None:
92
+ continue
93
+ result = classify(report_for(request.source_ref))
94
+ if result.kind is not None:
95
+ yield request, result
96
+
97
+
98
+ def payment_actor(
99
+ value: str, *, payer_account: str | None, payee_account: str | None,
100
+ buyer: ActorT, seller: ActorT, authority_account: str | None, authority: ActorT | None,
101
+ ) -> ActorT:
102
+ """Match accepted opaque accounts, never parse one as a marketplace identity."""
103
+ if payer_account is not None and value == payer_account:
104
+ return buyer
105
+ if value == "terms" or payee_account is not None and value == payee_account:
106
+ return seller
107
+ if authority_account is not None and value == authority_account and authority is not None:
108
+ return authority
109
+ raise ValueError("unrecognized payment actor")
110
+
111
+
112
+ def classify_site_end(
113
+ event: SiteEnd, *, seller: Any, term_end: int, available: bool,
114
+ commands: list[CommandEnd], termination_ref: str,
115
+ ) -> SiteClassification:
116
+ """Correlate exact commands, preserving unresolved and independent sources."""
117
+ ref = "site-event:" + event.event_id
118
+ for command in commands:
119
+ commanded = (
120
+ command.kind == "terminate" and event.reason == command.command_ref
121
+ and (event.caller == seller or (
122
+ event.caller is None and event.cause == "release"
123
+ and event.source_state in {"reserved", "leased"} and not available
124
+ )) and command.at <= event.effective_at
125
+ ) or (
126
+ command.kind == "truncate" and event.deadline_phase == "lease"
127
+ and event.claimed_deadline == event.effective_at == command.at
128
+ )
129
+ if commanded:
130
+ # An echo is the same end even when its controlling source is a
131
+ # failure. Do not file the financial consequence a second time.
132
+ return SiteClassification(
133
+ command.classification, [ref, command.source_ref, *command.evidence_refs],
134
+ command.source_ref,
135
+ )
136
+ if event.deadline_phase == "lease" and event.claimed_deadline == event.effective_at == term_end:
137
+ return SiteClassification("terms", [ref])
138
+ if (event.deadline_phase == "reservation" and event.claimed_deadline == event.effective_at
139
+ and not available):
140
+ return SiteClassification("provisioning_failure", [ref])
141
+ if event.reason == termination_ref:
142
+ return SiteClassification(None, [ref])
143
+ if event.cause in {"termination", "force_release"}:
144
+ return SiteClassification("unentitled_withdrawal", [ref])
145
+ # Release/teardown failures can precede the authority end that caused them.
146
+ return SiteClassification(None, [ref])
File without changes
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.5
2
+ Name: arkhai-compute
3
+ Version: 0.2.0
4
+ Summary: Compute-family market vocabulary shared by the VM and bare-metal domains.
5
+ License-Expression: MIT
6
+ Requires-Python: <3.14,>=3.12
7
+ Requires-Dist: arkhai-kit-capability-shape>=0.3.0
@@ -0,0 +1,7 @@
1
+ arkhai_compute/__init__.py,sha256=nKgxvCmNjtKfvSaWL7hWIm_w9Kux7EvW1XvjVKFW1Os,494
2
+ arkhai_compute/capability_schema.py,sha256=7rqb1o6NUoeaoT5q5OIWR9O-9iKHJcIzFVzdXJzyoOw,2101
3
+ arkhai_compute/end_classification.py,sha256=COTU1c7HcPUCRhJyBNEcatQ1T7wK7l9GUiAvimQkO0E,5496
4
+ arkhai_compute/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ arkhai_compute-0.2.0.dist-info/METADATA,sha256=N-gNMcp9QKWe74d-iDO6HmMhAGtP8HuuL6q5msWWx1U,245
6
+ arkhai_compute-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
7
+ arkhai_compute-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any