cloudfit-core 0.1.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.
cloudfit/__init__.py ADDED
@@ -0,0 +1,34 @@
1
+ """cloudfit-core: Cloud-agnostic machine type scoring engine."""
2
+
3
+ from .models import (
4
+ WorkloadProfile,
5
+ MachineType,
6
+ ScoredInstance,
7
+ OptimizeFor,
8
+ Archetype,
9
+ DiskSpec,
10
+ GPUSpec,
11
+ SchedulingSpec,
12
+ )
13
+ from .scorer import rank, score_instance, score
14
+ from .filter import hard_floor_check, apply_floors
15
+ from .disk import compute_disk_tb, compute_disk_breakdown, list_sequencers
16
+ from .yaml_loader import from_yaml, from_dict
17
+
18
+ __version__ = "0.1.0"
19
+ __author__ = "Chaitanya Krishna Kasaraneni"
20
+ __license__ = "Apache-2.0"
21
+
22
+ __all__ = [
23
+ # models
24
+ "WorkloadProfile", "MachineType", "ScoredInstance",
25
+ "OptimizeFor", "Archetype", "DiskSpec", "GPUSpec", "SchedulingSpec",
26
+ # scorer — both names are public API
27
+ "rank", "score_instance", "score",
28
+ # filter
29
+ "hard_floor_check", "apply_floors",
30
+ # disk
31
+ "compute_disk_tb", "compute_disk_breakdown", "list_sequencers",
32
+ # yaml
33
+ "from_yaml", "from_dict",
34
+ ]
cloudfit/disk.py ADDED
@@ -0,0 +1,191 @@
1
+ """Dynamic disk sizing for sequencing workloads.
2
+
3
+ Computes total scratch disk required for a sequencing demultiplexing run
4
+ from experiment parameters rather than using a fixed estimate.
5
+
6
+ Disk components
7
+ ---------------
8
+ input_gb Raw sequencer output (compressed or uncompressed format)
9
+ output_gb Demultiplexed output files (FASTQ)
10
+ tmp_gb Working directory during processing (~35% of input)
11
+ retained_input_gb Raw input kept post-run (if retain_input=True)
12
+
13
+ Compressed vs uncompressed input
14
+ ---------------------------------
15
+ Some sequencers write a compressed input format that is ~4x smaller
16
+ than the uncompressed equivalent before demultiplexing. Output file
17
+ size is the same regardless of input format.
18
+
19
+ Safety margin
20
+ -------------
21
+ Applied to the total before returning. Default 20%.
22
+ """
23
+
24
+ from __future__ import annotations
25
+ from dataclasses import dataclass
26
+
27
+
28
+ @dataclass
29
+ class _FlowcellProfile:
30
+ label: str
31
+ gb_per_lane: float
32
+ max_lanes: int
33
+ compressed: bool # True if sequencer writes compressed input format
34
+
35
+
36
+ _SEQUENCER_PROFILES: dict[str, list[_FlowcellProfile]] = {
37
+ "miseq": [
38
+ _FlowcellProfile("nano", gb_per_lane=0.8, max_lanes=1, compressed=False),
39
+ _FlowcellProfile("micro", gb_per_lane=1.5, max_lanes=1, compressed=False),
40
+ _FlowcellProfile("standard", gb_per_lane=15.0, max_lanes=1, compressed=False),
41
+ ],
42
+ "nextseq": [
43
+ _FlowcellProfile("mid", gb_per_lane=40.0, max_lanes=4, compressed=False),
44
+ _FlowcellProfile("high", gb_per_lane=120.0, max_lanes=4, compressed=False),
45
+ ],
46
+ "novaseq_6000": [
47
+ _FlowcellProfile("sp", gb_per_lane=200.0, max_lanes=2, compressed=False),
48
+ _FlowcellProfile("s1", gb_per_lane=400.0, max_lanes=2, compressed=False),
49
+ _FlowcellProfile("s2", gb_per_lane=500.0, max_lanes=4, compressed=False),
50
+ _FlowcellProfile("s4", gb_per_lane=1200.0, max_lanes=4, compressed=False),
51
+ ],
52
+ "novaseq_x": [
53
+ _FlowcellProfile("1.5b", gb_per_lane=380.0, max_lanes=2, compressed=True),
54
+ _FlowcellProfile("10b", gb_per_lane=600.0, max_lanes=8, compressed=True),
55
+ _FlowcellProfile("25b", gb_per_lane=1500.0, max_lanes=8, compressed=True),
56
+ ],
57
+ "hiseq": [
58
+ _FlowcellProfile("rapid", gb_per_lane=150.0, max_lanes=2, compressed=False),
59
+ _FlowcellProfile("high", gb_per_lane=400.0, max_lanes=8, compressed=False),
60
+ ],
61
+ }
62
+
63
+ # Compressed input format is ~4x smaller than uncompressed equivalent
64
+ _COMPRESSION_FACTOR = 0.25
65
+
66
+ # Output files are ~1.4x the (uncompressed-equivalent) input size
67
+ _OUTPUT_MULTIPLIER = 1.40
68
+
69
+ # Reads that don't match any sample add ~8% to output
70
+ _UNDETERMINED_FACTOR = 1.08
71
+
72
+ # Temp/working directory is ~35% of input during processing
73
+ _TMP_FRACTION = 0.35
74
+
75
+
76
+ @dataclass
77
+ class DiskBreakdown:
78
+ """Detailed breakdown of disk components in GB."""
79
+ input_gb: float
80
+ output_gb: float
81
+ tmp_gb: float
82
+ retained_input_gb: float
83
+ subtotal_gb: float
84
+ safety_margin: float
85
+ total_gb: float
86
+
87
+ @property
88
+ def total_tb(self) -> float:
89
+ return self.total_gb / 1000
90
+
91
+
92
+ def compute_disk_tb(
93
+ sequencer: str,
94
+ flowcell: str,
95
+ lanes: int,
96
+ *,
97
+ samples: int = 96,
98
+ retain_input: bool = False,
99
+ keep_undetermined: bool = False,
100
+ safety_margin: float = 0.20,
101
+ ) -> float:
102
+ """Compute total scratch disk required in TB.
103
+
104
+ Args:
105
+ sequencer: Sequencer model key (e.g. "novaseq_6000", "miseq")
106
+ flowcell: Flowcell type key (e.g. "s4", "nano", "high")
107
+ lanes: Number of lanes used in this run
108
+ samples: Number of samples (reserved for future use)
109
+ retain_input: If True, raw input files are kept post-run
110
+ keep_undetermined: If True, unmatched reads are written to disk (+8%)
111
+ safety_margin: Fractional headroom added to total (default 0.20)
112
+
113
+ Returns:
114
+ Total disk required in TB (with safety margin applied).
115
+
116
+ Raises:
117
+ ValueError: If sequencer or flowcell key is not recognised.
118
+ """
119
+ breakdown = compute_disk_breakdown(
120
+ sequencer=sequencer,
121
+ flowcell=flowcell,
122
+ lanes=lanes,
123
+ samples=samples,
124
+ retain_input=retain_input,
125
+ keep_undetermined=keep_undetermined,
126
+ safety_margin=safety_margin,
127
+ )
128
+ return round(breakdown.total_tb, 2)
129
+
130
+
131
+ def compute_disk_breakdown(
132
+ sequencer: str,
133
+ flowcell: str,
134
+ lanes: int,
135
+ *,
136
+ samples: int = 96,
137
+ retain_input: bool = False,
138
+ keep_undetermined: bool = False,
139
+ safety_margin: float = 0.20,
140
+ ) -> DiskBreakdown:
141
+ """Compute a full disk breakdown with all components in GB."""
142
+ seq_key = sequencer.lower().replace("-", "_").replace(" ", "_")
143
+ fc_key = flowcell.lower().replace("-", "_").replace(" ", "_")
144
+
145
+ if seq_key not in _SEQUENCER_PROFILES:
146
+ raise ValueError(
147
+ f"Unknown sequencer {sequencer!r}. "
148
+ f"Known: {list(_SEQUENCER_PROFILES)}"
149
+ )
150
+
151
+ profiles = _SEQUENCER_PROFILES[seq_key]
152
+ fc_profile = next((p for p in profiles if p.label == fc_key), None)
153
+ if fc_profile is None:
154
+ known = [p.label for p in profiles]
155
+ raise ValueError(
156
+ f"Unknown flowcell {flowcell!r} for {sequencer!r}. "
157
+ f"Known flowcells: {known}"
158
+ )
159
+
160
+ lanes = min(lanes, fc_profile.max_lanes)
161
+
162
+ # Apply compression factor to input only — output is always full size
163
+ compression = _COMPRESSION_FACTOR if fc_profile.compressed else 1.0
164
+ input_gb = fc_profile.gb_per_lane * lanes * compression
165
+
166
+ undetermined_factor = _UNDETERMINED_FACTOR if keep_undetermined else 1.0
167
+ output_gb = input_gb * _OUTPUT_MULTIPLIER * undetermined_factor
168
+
169
+ tmp_gb = input_gb * _TMP_FRACTION
170
+ retained_input_gb = input_gb if retain_input else 0.0
171
+
172
+ subtotal_gb = input_gb + output_gb + tmp_gb + retained_input_gb
173
+ total_gb = subtotal_gb * (1 + safety_margin)
174
+
175
+ return DiskBreakdown(
176
+ input_gb=round(input_gb, 1),
177
+ output_gb=round(output_gb, 1),
178
+ tmp_gb=round(tmp_gb, 1),
179
+ retained_input_gb=round(retained_input_gb, 1),
180
+ subtotal_gb=round(subtotal_gb, 1),
181
+ safety_margin=safety_margin,
182
+ total_gb=round(total_gb, 1),
183
+ )
184
+
185
+
186
+ def list_sequencers() -> dict[str, list[str]]:
187
+ """Return all known sequencer/flowcell combinations."""
188
+ return {
189
+ seq: [fc.label for fc in profiles]
190
+ for seq, profiles in _SEQUENCER_PROFILES.items()
191
+ }
cloudfit/filter.py ADDED
@@ -0,0 +1,76 @@
1
+ """Hard floor filters for cloudfit-core.
2
+
3
+ Hard floors run before scoring and eliminate instances that cannot
4
+ satisfy the workload requirements, regardless of their composite score.
5
+ """
6
+
7
+ from __future__ import annotations
8
+ from .models import WorkloadProfile, MachineType
9
+
10
+
11
+ def hard_floor_check(instance: MachineType, profile: WorkloadProfile) -> str | None:
12
+ """Return a disqualify reason string if the instance fails any hard floor.
13
+
14
+ Returns None if the instance passes all floors and is eligible for scoring.
15
+
16
+ Floors checked (in order):
17
+ 1. RAM — instance.ram_gb >= profile.ram_floor_gb (or ram_gb if no floor set)
18
+ 2. vCPU — instance.vcpu >= profile.vcpu
19
+ 3. GPU presence — if profile.gpu.required, instance must have gpu_count > 0
20
+ 4. GPU VRAM — if profile.gpu.vram_gb set, instance.gpu_vram_gb must meet it
21
+ 5. Status — tombstoned instances are always disqualified
22
+ """
23
+ # 1. RAM floor
24
+ floor_ram = profile.ram_floor_gb if profile.ram_floor_gb is not None else profile.ram_gb
25
+ if instance.ram_gb < floor_ram:
26
+ return (
27
+ f"RAM {instance.ram_gb:.0f} GB < required {floor_ram:.0f} GB"
28
+ )
29
+
30
+ # 2. vCPU floor
31
+ if instance.vcpu < profile.vcpu:
32
+ return f"vCPU {instance.vcpu} < required {profile.vcpu}"
33
+
34
+ # 3. GPU presence
35
+ if profile.gpu.required and instance.gpu_count == 0:
36
+ return "GPU required but instance has no GPU"
37
+
38
+ # 4. GPU VRAM
39
+ if (
40
+ profile.gpu.required
41
+ and profile.gpu.vram_gb is not None
42
+ and instance.gpu_vram_gb is not None
43
+ and instance.gpu_vram_gb < profile.gpu.vram_gb
44
+ ):
45
+ return (
46
+ f"GPU VRAM {instance.gpu_vram_gb} GB < required {profile.gpu.vram_gb} GB"
47
+ )
48
+
49
+ # 5. Tombstoned instances are never recommended
50
+ if instance.status == "tombstoned":
51
+ return f"Instance {instance.id!r} is tombstoned — no longer available from {instance.provider}"
52
+
53
+ return None
54
+
55
+
56
+ def apply_floors(
57
+ instances: list[MachineType],
58
+ profile: WorkloadProfile,
59
+ ) -> tuple[list[MachineType], list[tuple[MachineType, str]]]:
60
+ """Partition instances into (qualified, disqualified) lists.
61
+
62
+ Returns:
63
+ qualified: instances that passed all hard floors
64
+ disqualified: list of (instance, reason) tuples that failed
65
+ """
66
+ qualified: list[MachineType] = []
67
+ disqualified: list[tuple[MachineType, str]] = []
68
+
69
+ for inst in instances:
70
+ reason = hard_floor_check(inst, profile)
71
+ if reason is None:
72
+ qualified.append(inst)
73
+ else:
74
+ disqualified.append((inst, reason))
75
+
76
+ return qualified, disqualified
cloudfit/models.py ADDED
@@ -0,0 +1,84 @@
1
+ """Core data models for cloudfit-core."""
2
+
3
+ from __future__ import annotations
4
+ from enum import Enum
5
+ from typing import Optional
6
+ from pydantic import BaseModel, Field
7
+
8
+
9
+ class OptimizeFor(str, Enum):
10
+ cost = "cost"
11
+ balanced = "balanced"
12
+ performance = "performance"
13
+ availability = "availability"
14
+
15
+
16
+ class Archetype(str, Enum):
17
+ io = "io" # disk-saturating (BCLConvert, BWA)
18
+ cpu = "cpu" # thread-parallel (GATK, Trinity)
19
+ mem = "mem" # large index / reference (Kraken2, Cell Ranger)
20
+ gpu = "gpu" # GPU inference (AlphaFold, Parabricks)
21
+ burst = "burst" # scatter-gather fleet (Nextflow, Snakemake)
22
+
23
+
24
+ class GPUSpec(BaseModel):
25
+ required: bool = False
26
+ vram_gb: Optional[int] = None
27
+
28
+
29
+ class DiskSpec(BaseModel):
30
+ sizing: str = "static"
31
+ scratch_tb: Optional[float] = None
32
+ preferred: str = "network_ssd"
33
+ safety_margin: float = 0.20
34
+
35
+
36
+ class SchedulingSpec(BaseModel):
37
+ spot: bool = False
38
+ restart_tolerant: bool = False
39
+
40
+
41
+ class WorkloadProfile(BaseModel):
42
+ """Describes the resource requirements of a computational workload."""
43
+ vcpu: int = Field(gt=0)
44
+ ram_gb: float = Field(gt=0)
45
+ ram_floor_gb: Optional[float] = None
46
+ workload: str = "generic"
47
+ archetype: Archetype = Archetype.cpu
48
+ tool: Optional[str] = None
49
+ parallelism: str = "sample"
50
+ disk: DiskSpec = Field(default_factory=DiskSpec)
51
+ gpu: GPUSpec = Field(default_factory=GPUSpec)
52
+ scheduling: SchedulingSpec = Field(default_factory=SchedulingSpec)
53
+ optimize_for: OptimizeFor = OptimizeFor.balanced
54
+ providers: list[str] = Field(default_factory=lambda: ["gcp", "aws"])
55
+ weights: Optional[dict[str, float]] = None
56
+
57
+
58
+ class MachineType(BaseModel):
59
+ """A cloud provider machine type with specs and pricing."""
60
+ id: str
61
+ provider: str
62
+ vcpu: int
63
+ ram_gb: float
64
+ price_hr: float
65
+ local_ssd_tb: float = 0.0
66
+ gpu_count: int = 0
67
+ gpu_vram_gb: Optional[int] = None
68
+ region: str = "us-central1"
69
+ status: str = "active"
70
+ generation: Optional[str] = None
71
+
72
+
73
+ class ScoredInstance(BaseModel):
74
+ """A MachineType with its composite score and sub-scores."""
75
+ instance: MachineType
76
+ score: float
77
+ cost_score: float
78
+ perf_score: float
79
+ avail_score: float
80
+ disqualified: bool = False
81
+ disqualify_reason: Optional[str] = None
82
+
83
+ def __lt__(self, other: "ScoredInstance") -> bool:
84
+ return self.score < other.score
@@ -0,0 +1,23 @@
1
+ """Abstract base class for cloudfit provider plugins."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ from ..models import MachineType
5
+
6
+
7
+ class Provider(ABC):
8
+ """Interface that all cloudfit provider packages must implement."""
9
+
10
+ @abstractmethod
11
+ def fetch_instances(self, region: str) -> list[MachineType]:
12
+ """Fetch all available machine types for a region."""
13
+ ...
14
+
15
+ @abstractmethod
16
+ def get_pricing(self, instance_id: str, region: str) -> float:
17
+ """Return on-demand price per hour for an instance in a region."""
18
+ ...
19
+
20
+ @abstractmethod
21
+ def get_availability(self, instance_id: str, region: str) -> float:
22
+ """Return availability score 0.0–1.0 (1.0 = actively maintained)."""
23
+ ...
cloudfit/scorer.py ADDED
@@ -0,0 +1,129 @@
1
+ """Weighted scoring engine for cloudfit-core."""
2
+
3
+ from __future__ import annotations
4
+ from .models import WorkloadProfile, MachineType, ScoredInstance, OptimizeFor
5
+
6
+ WEIGHT_MATRIX: dict[str, dict[str, float]] = {
7
+ OptimizeFor.cost: {"cost": 0.70, "perf": 0.20, "avail": 0.10},
8
+ OptimizeFor.balanced: {"cost": 0.33, "perf": 0.34, "avail": 0.33},
9
+ OptimizeFor.performance: {"cost": 0.10, "perf": 0.80, "avail": 0.10},
10
+ OptimizeFor.availability: {"cost": 0.10, "perf": 0.20, "avail": 0.70},
11
+ }
12
+
13
+ # Max price reference for normalizing cost score (~$35/hr covers most instances)
14
+ _MAX_PRICE_HR = 35.0
15
+
16
+ # Normalize long-form weight keys to short internal keys.
17
+ # Users may pass "performance" or "availability" (as documented in README);
18
+ # the engine uses "perf" and "avail" internally.
19
+ _KEY_ALIASES: dict[str, str] = {
20
+ "performance": "perf",
21
+ "availability": "avail",
22
+ }
23
+
24
+
25
+ def _normalize_weights(weights: dict[str, float]) -> dict[str, float]:
26
+ """Accept both short (perf/avail) and long (performance/availability) keys."""
27
+ return {_KEY_ALIASES.get(k, k): v for k, v in weights.items()}
28
+
29
+
30
+ def _cost_score(instance: MachineType) -> float:
31
+ """Lower price → higher score. Normalized 0–1."""
32
+ return max(0.0, 1.0 - (instance.price_hr / _MAX_PRICE_HR))
33
+
34
+
35
+ def _perf_score(instance: MachineType, profile: WorkloadProfile) -> float:
36
+ """Higher vCPU + RAM density relative to request → higher score."""
37
+ vcpu_ratio = min(instance.vcpu / max(profile.vcpu, 1), 2.0) / 2.0
38
+ ram_ratio = min(instance.ram_gb / max(profile.ram_gb, 1), 2.0) / 2.0
39
+ return vcpu_ratio * 0.5 + ram_ratio * 0.5
40
+
41
+
42
+ def _avail_score(instance: MachineType) -> float:
43
+ """Active > deprecated > tombstoned."""
44
+ return {"active": 1.0, "deprecated": 0.4, "tombstoned": 0.0}.get(
45
+ instance.status, 0.5
46
+ )
47
+
48
+
49
+ def _hard_floor_check(instance: MachineType, profile: WorkloadProfile) -> str | None:
50
+ """Return a disqualify reason string if this instance fails any hard floor."""
51
+ floor_ram = profile.ram_floor_gb if profile.ram_floor_gb is not None else profile.ram_gb
52
+ if instance.ram_gb < floor_ram:
53
+ return f"RAM {instance.ram_gb} GB < required {floor_ram} GB"
54
+ if instance.vcpu < profile.vcpu:
55
+ return f"vCPU {instance.vcpu} < required {profile.vcpu}"
56
+ if profile.gpu.required:
57
+ if instance.gpu_count == 0:
58
+ return "GPU required but not available"
59
+ if (
60
+ profile.gpu.vram_gb is not None
61
+ and instance.gpu_vram_gb is not None
62
+ and instance.gpu_vram_gb < profile.gpu.vram_gb
63
+ ):
64
+ return (
65
+ f"GPU VRAM {instance.gpu_vram_gb} GB "
66
+ f"< required {profile.gpu.vram_gb} GB"
67
+ )
68
+ if instance.status == "tombstoned":
69
+ return f"Instance {instance.id!r} is tombstoned — no longer available"
70
+ return None
71
+
72
+
73
+ def score_instance(instance: MachineType, profile: WorkloadProfile) -> ScoredInstance:
74
+ """Score a single instance against a workload profile.
75
+
76
+ Returns a ScoredInstance with composite score and sub-scores.
77
+ Disqualified instances have score=0.0 and disqualified=True.
78
+ """
79
+ reason = _hard_floor_check(instance, profile)
80
+ if reason:
81
+ return ScoredInstance(
82
+ instance=instance, score=0.0,
83
+ cost_score=0.0, perf_score=0.0, avail_score=0.0,
84
+ disqualified=True, disqualify_reason=reason,
85
+ )
86
+
87
+ raw_weights = profile.weights or WEIGHT_MATRIX[profile.optimize_for]
88
+ weights = _normalize_weights(raw_weights)
89
+
90
+ c = _cost_score(instance)
91
+ p = _perf_score(instance, profile)
92
+ a = _avail_score(instance)
93
+
94
+ composite = (
95
+ weights.get("cost", 0.33) * c
96
+ + weights.get("perf", 0.34) * p
97
+ + weights.get("avail", 0.33) * a
98
+ )
99
+
100
+ return ScoredInstance(
101
+ instance=instance,
102
+ score=round(composite, 4),
103
+ cost_score=round(c, 4),
104
+ perf_score=round(p, 4),
105
+ avail_score=round(a, 4),
106
+ )
107
+
108
+
109
+ # Alias — both names are public API
110
+ score = score_instance
111
+
112
+
113
+ def rank(
114
+ profile: WorkloadProfile,
115
+ candidates: list[MachineType],
116
+ ) -> list[ScoredInstance]:
117
+ """Score and rank all candidates.
118
+
119
+ Qualified instances are returned first, sorted by score descending.
120
+ Disqualified instances appear at the end (score=0.0).
121
+ """
122
+ scored = [score_instance(m, profile) for m in candidates]
123
+ qualified = sorted(
124
+ [s for s in scored if not s.disqualified],
125
+ key=lambda s: s.score,
126
+ reverse=True,
127
+ )
128
+ disqualified = [s for s in scored if s.disqualified]
129
+ return qualified + disqualified
@@ -0,0 +1,149 @@
1
+ """YAML workload schema loader for cloudfit-core.
2
+
3
+ Loads a workload profile from a YAML file or dict and returns
4
+ a validated WorkloadProfile instance.
5
+
6
+ Schema example
7
+ --------------
8
+ workload:
9
+ type: io-intensive
10
+ archetype: io
11
+ parallelism: lane
12
+
13
+ resources:
14
+ vcpu: 60
15
+ ram_gb: 224
16
+ disk:
17
+ sizing: dynamic
18
+ scratch_tb: 18
19
+ preferred: local_ssd_first
20
+ safety_margin: 0.20
21
+ gpu:
22
+ required: false
23
+
24
+ scheduling:
25
+ spot: false
26
+ restart_tolerant: false
27
+
28
+ optimize_for: balanced
29
+ providers:
30
+ - gcp
31
+ - aws
32
+ """
33
+
34
+ from __future__ import annotations
35
+ from pathlib import Path
36
+ from typing import Any
37
+
38
+ try:
39
+ import yaml
40
+ except ImportError as exc:
41
+ raise ImportError(
42
+ "PyYAML is required for from_yaml(). "
43
+ "Install it with: pip install pyyaml"
44
+ ) from exc
45
+
46
+ from .models import (
47
+ WorkloadProfile,
48
+ DiskSpec,
49
+ GPUSpec,
50
+ SchedulingSpec,
51
+ OptimizeFor,
52
+ Archetype,
53
+ )
54
+
55
+
56
+ def from_yaml(path: str | Path) -> WorkloadProfile:
57
+ """Load a WorkloadProfile from a YAML file.
58
+
59
+ Args:
60
+ path: Path to the YAML file.
61
+
62
+ Returns:
63
+ A validated WorkloadProfile instance.
64
+
65
+ Raises:
66
+ FileNotFoundError: If the file does not exist.
67
+ ValueError: If required fields are missing or invalid.
68
+ """
69
+ path = Path(path)
70
+ if not path.exists():
71
+ raise FileNotFoundError(f"Workload file not found: {path}")
72
+
73
+ with path.open() as f:
74
+ raw = yaml.safe_load(f)
75
+
76
+ return from_dict(raw)
77
+
78
+
79
+ def from_dict(data: dict[str, Any]) -> WorkloadProfile:
80
+ """Parse a WorkloadProfile from a plain dict (e.g. parsed JSON or YAML).
81
+
82
+ Accepts both flat and nested schemas:
83
+
84
+ Nested (preferred):
85
+ workload:
86
+ resources:
87
+ vcpu: 60
88
+ ram_gb: 224
89
+
90
+ Flat (also accepted):
91
+ vcpu: 60
92
+ ram_gb: 224
93
+
94
+ Args:
95
+ data: Raw dict from YAML/JSON.
96
+
97
+ Returns:
98
+ A validated WorkloadProfile.
99
+ """
100
+ # Support both top-level "workload:" key and flat dict
101
+ w = data.get("workload", data)
102
+ resources = w.get("resources", w)
103
+
104
+ # Disk spec
105
+ disk_raw = resources.get("disk", {})
106
+ disk = DiskSpec(
107
+ sizing=disk_raw.get("sizing", "static"),
108
+ scratch_tb=disk_raw.get("scratch_tb"),
109
+ preferred=disk_raw.get("preferred", "network_ssd"),
110
+ safety_margin=disk_raw.get("safety_margin", 0.20),
111
+ )
112
+
113
+ # GPU spec
114
+ gpu_raw = resources.get("gpu", {})
115
+ gpu = GPUSpec(
116
+ required=gpu_raw.get("required", False),
117
+ vram_gb=gpu_raw.get("vram_gb"),
118
+ )
119
+
120
+ # Scheduling spec
121
+ sched_raw = w.get("scheduling", {})
122
+ scheduling = SchedulingSpec(
123
+ spot=sched_raw.get("spot", False),
124
+ restart_tolerant=sched_raw.get("restart_tolerant", False),
125
+ )
126
+
127
+ vcpu = resources.get("vcpu")
128
+ ram_gb = resources.get("ram_gb")
129
+
130
+ if vcpu is None:
131
+ raise ValueError("workload.resources.vcpu is required")
132
+ if ram_gb is None:
133
+ raise ValueError("workload.resources.ram_gb is required")
134
+
135
+ return WorkloadProfile(
136
+ vcpu=int(vcpu),
137
+ ram_gb=float(ram_gb),
138
+ ram_floor_gb=resources.get("ram_floor_gb"),
139
+ workload=w.get("type", "generic"),
140
+ archetype=Archetype(w.get("archetype", "cpu")),
141
+ tool=w.get("tool"),
142
+ parallelism=w.get("parallelism", "sample"),
143
+ disk=disk,
144
+ gpu=gpu,
145
+ scheduling=scheduling,
146
+ optimize_for=OptimizeFor(w.get("optimize_for", "balanced")),
147
+ providers=w.get("providers", ["gcp", "aws"]),
148
+ weights=w.get("weights"),
149
+ )
@@ -0,0 +1,346 @@
1
+ Metadata-Version: 2.4
2
+ Name: cloudfit-core
3
+ Version: 0.1.0
4
+ Summary: Cloud-agnostic machine type scoring engine for computational workloads
5
+ Project-URL: Homepage, https://github.com/cloudfit-io/cloudfit-core
6
+ Project-URL: Repository, https://github.com/cloudfit-io/cloudfit-core
7
+ Project-URL: Bug Tracker, https://github.com/cloudfit-io/cloudfit-core/issues
8
+ Project-URL: Google Scholar, https://scholar.google.com/citations?user=Y2S8D2UAAAAJ
9
+ Project-URL: ORCID, https://orcid.org/0000-0001-5792-1095
10
+ Author-email: Chaitanya Krishna Kasaraneni <kc.kasaraneni@gmail.com>
11
+ License: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: aws,azure,bioinformatics,cloud,gcp,genomics,instance-recommendation,machine-type,terraform
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
24
+ Classifier: Topic :: System :: Systems Administration
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: pydantic>=2.0
27
+ Requires-Dist: pyyaml>=6.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: mypy; extra == 'dev'
30
+ Requires-Dist: pytest-cov; extra == 'dev'
31
+ Requires-Dist: pytest>=7.0; extra == 'dev'
32
+ Requires-Dist: ruff; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # cloudfit-core
36
+
37
+ [![PyPI version](https://img.shields.io/pypi/v/cloudfit-core)](https://pypi.org/project/cloudfit-core/)
38
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue)](https://pypi.org/project/cloudfit-core/)
39
+ [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-green)](LICENSE)
40
+ [![Tests](https://github.com/cloudfit-io/cloudfit-core/actions/workflows/test.yml/badge.svg)](https://github.com/cloudfit-io/cloudfit-core/actions)
41
+
42
+ **Cloud-agnostic machine type scoring engine for computational workloads.**
43
+
44
+ `cloudfit-core` is the foundation of the [cloudfit](https://github.com/cloudfit-io) ecosystem — a pure Python library that, given a workload profile, scores and ranks available cloud instances across providers. No cloud credentials required. No API calls. Just a workload spec in, ranked recommendations out.
45
+
46
+ ---
47
+
48
+ ## The problem
49
+
50
+ Teams hardcode instance types (`c2-standard-60`, `c7i.16xlarge`) in infrastructure-as-code. When providers deprecate them or release better generations, nothing updates — costs drift and performance degrades silently. There is no open-source tool that takes a workload description and returns the best available instance across AWS, GCP, and Azure with explainable scoring.
51
+
52
+ cloudfit-core is that scoring engine.
53
+
54
+ ---
55
+
56
+ ## Installation
57
+
58
+ ```bash
59
+ pip install cloudfit-core
60
+ ```
61
+
62
+ Requires Python 3.9+.
63
+
64
+ ---
65
+
66
+ ## Quick start
67
+
68
+ ```python
69
+ from cloudfit import WorkloadProfile, MachineType, rank
70
+
71
+ # Define your workload
72
+ profile = WorkloadProfile(
73
+ vcpu=60,
74
+ ram_gb=224,
75
+ workload="io-intensive",
76
+ archetype="io", # io | cpu | mem | gpu | burst
77
+ optimize_for="balanced", # cost | performance | availability | balanced
78
+ )
79
+
80
+ # Provide candidate instances (from a cloudfit-provider-* package or your own list)
81
+ candidates = [
82
+ MachineType(id="c2-standard-60", provider="gcp", vcpu=60, ram_gb=240, price_hr=3.13),
83
+ MachineType(id="c3d-standard-60-lssd", provider="gcp", vcpu=60, ram_gb=240, price_hr=3.39),
84
+ MachineType(id="t2d-standard-60", provider="gcp", vcpu=60, ram_gb=240, price_hr=2.31),
85
+ MachineType(id="c7i.24xlarge", provider="aws", vcpu=96, ram_gb=192, price_hr=4.28),
86
+ ]
87
+
88
+ # Score and rank
89
+ results = rank(profile, candidates)
90
+ for r in results:
91
+ print(f"{r.instance.id:30s} score={r.score:.2f} ${r.instance.price_hr:.2f}/hr")
92
+ ```
93
+
94
+ Output:
95
+ ```
96
+ t2d-standard-60 score=0.81 $2.31/hr
97
+ c2-standard-60 score=0.81 $3.13/hr
98
+ c3d-standard-60-lssd score=0.80 $3.39/hr
99
+ c7i.24xlarge score=0.00 $4.28/hr
100
+ ```
101
+
102
+ `c7i.24xlarge` scores `0.00` and ranks last because its 192 GB RAM is below the
103
+ requested 224 GB — it's eliminated by the hard floor filter, not just ranked low
104
+ (see [How scoring works](#how-scoring-works)).
105
+
106
+ ---
107
+
108
+ ## How scoring works
109
+
110
+ Every recommendation runs through the same weighted scoring function:
111
+
112
+ ```
113
+ score = w_cost × cost_score + w_perf × perf_score + w_avail × avail_score
114
+ ```
115
+
116
+ The `optimize_for` mode sets the weights:
117
+
118
+ | Mode | w_cost | w_perf | w_avail | Best for |
119
+ |---|---|---|---|---|
120
+ | `cost` | 0.70 | 0.20 | 0.10 | Batch jobs, dev environments |
121
+ | `balanced` | 0.33 | 0.34 | 0.33 | Default — production workloads |
122
+ | `performance` | 0.10 | 0.80 | 0.10 | Latency-sensitive, GPU inference |
123
+ | `availability` | 0.10 | 0.20 | 0.70 | Long-running jobs, deprecation risk |
124
+
125
+ **Hard floor filters** run before scoring — instances that don't meet minimum RAM, vCPU, or GPU requirements are eliminated entirely, not just ranked low.
126
+
127
+ Advanced users can override weights directly:
128
+
129
+ ```python
130
+ profile = WorkloadProfile(
131
+ vcpu=60,
132
+ ram_gb=224,
133
+ # Both short and long key spellings are accepted:
134
+ # short: {"cost": 0.5, "perf": 0.4, "avail": 0.1}
135
+ # long: {"cost": 0.5, "performance": 0.4, "availability": 0.1}
136
+ weights={"cost": 0.5, "performance": 0.4, "availability": 0.1}
137
+ )
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Workload archetypes
143
+
144
+ cloudfit-core understands five resource archetypes, each reflecting a different dominant constraint:
145
+
146
+ | Archetype | Dominant constraint | Typical workloads |
147
+ |---|---|---|
148
+ | `io` | Disk throughput | Sequencing demultiplexing, short-read alignment |
149
+ | `cpu` | Thread parallelism | Variant calling, de novo assembly, quantification |
150
+ | `mem` | RAM capacity | Metagenomics classification, single-cell RNA-seq, Hi-C |
151
+ | `gpu` | GPU VRAM | Protein structure prediction, GPU variant calling, basecalling |
152
+ | `burst` | Fleet × small instances | Nextflow pipelines, Snakemake DAGs, WDL scatter-gather |
153
+
154
+ In this release the archetype is recorded on the workload profile for classification and downstream tooling; scoring weights are driven by `optimize_for`. Archetype-aware weighting and fleet-vs-single-instance recommendations (e.g. many small spot instances for `burst`) are planned for a future release.
155
+
156
+ ---
157
+
158
+ ## Dynamic disk sizing
159
+
160
+ For sequencing workloads, disk requirements scale with experiment parameters rather than being fixed. cloudfit-core computes disk from first principles:
161
+
162
+ ```python
163
+ from cloudfit import compute_disk_tb, WorkloadProfile, DiskSpec
164
+
165
+ disk_tb = compute_disk_tb(
166
+ sequencer="novaseq_6000",
167
+ flowcell="s4",
168
+ lanes=4,
169
+ retain_input=False, # if True, raw input files are kept post-run
170
+ keep_undetermined=False, # if True, unmatched reads written to disk (+8%)
171
+ safety_margin=0.20,
172
+ )
173
+ # → 15.84 TB
174
+
175
+ # Use the result when building your workload profile
176
+ profile = WorkloadProfile(
177
+ vcpu=60,
178
+ ram_gb=224,
179
+ workload="io-intensive",
180
+ archetype="io",
181
+ disk=DiskSpec(sizing="static", scratch_tb=disk_tb),
182
+ )
183
+ ```
184
+
185
+ `compute_disk_tb` is a standalone helper — call it before constructing your `WorkloadProfile` and pass the result into `DiskSpec.scratch_tb`.
186
+
187
+ ---
188
+
189
+ ## Workload YAML schema
190
+
191
+ ```yaml
192
+ workload:
193
+ type: io-intensive
194
+ archetype: io
195
+ parallelism: lane # lane | sample | interval | process | rule
196
+
197
+ resources:
198
+ vcpu: 60
199
+ ram_gb: 224
200
+ disk:
201
+ sizing: dynamic # "dynamic" computes from experiment params; "static" uses scratch_tb
202
+ preferred: local_ssd_first
203
+ gpu:
204
+ required: false
205
+
206
+ scheduling:
207
+ spot: false
208
+ restart_tolerant: false
209
+
210
+ optimize_for: balanced # cost | performance | availability | balanced
211
+ providers:
212
+ - gcp
213
+ - aws
214
+ ```
215
+
216
+ Load from file:
217
+
218
+ ```python
219
+ from cloudfit import from_yaml
220
+
221
+ profile = from_yaml("my-workload.yaml")
222
+ results = rank(profile, candidates)
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Provider plugins
228
+
229
+ `cloudfit-core` is the scoring engine only — it scores whatever instances you give it. Provider plugins fetch live instance data from cloud APIs on a schedule and feed the registry:
230
+
231
+ ```bash
232
+ pip install cloudfit-provider-gcp # fetches GCP Compute Engine machine types
233
+ pip install cloudfit-provider-aws # fetches AWS EC2 instance specs and pricing
234
+ ```
235
+
236
+ Each provider implements a simple interface:
237
+
238
+ ```python
239
+ from cloudfit.providers.base import Provider
240
+
241
+ class MyProvider(Provider):
242
+ def fetch_instances(self, region: str) -> list[MachineType]: ...
243
+ def get_pricing(self, instance_id: str, region: str) -> float: ...
244
+ def get_availability(self, instance_id: str, region: str) -> float: ...
245
+ ```
246
+
247
+ Want to add a provider? See [CONTRIBUTING.md](CONTRIBUTING.md).
248
+
249
+ ---
250
+
251
+ ## Terraform / OpenTofu integration
252
+
253
+ Once `cloudfit-api` is running, use the Terraform provider to resolve instance types at plan time:
254
+
255
+ ```hcl
256
+ data "cloudfit_recommendation" "demux_worker" {
257
+ vcpu = 60
258
+ ram_gb = 224
259
+ workload = "sequencing-demux"
260
+ optimize_for = "balanced"
261
+ }
262
+
263
+ resource "google_compute_instance" "worker" {
264
+ machine_type = data.cloudfit_recommendation.demux_worker.machine_type
265
+ }
266
+ ```
267
+
268
+ ---
269
+
270
+ ## Citing cloudfit-core
271
+
272
+ If you use cloudfit-core in your research, please cite it:
273
+
274
+ ```bibtex
275
+ @software{kasaraneni2026cloudfit,
276
+ author = {Kasaraneni, Chaitanya Krishna},
277
+ title = {cloudfit-core: Cloud-agnostic machine type scoring engine
278
+ for computational workloads},
279
+ year = {2026},
280
+ publisher = {GitHub},
281
+ url = {https://github.com/cloudfit-io/cloudfit-core},
282
+ orcid = {0000-0001-5792-1095}
283
+ }
284
+ ```
285
+
286
+ GitHub also shows a **Cite this repository** button in the sidebar (powered by `CITATION.cff`).
287
+
288
+ ---
289
+
290
+ ## Related publications
291
+
292
+ - Kasaraneni, C.K. et al. (2025). *AI-Driven Drug Repurposing: A Graph Neural Network and Self-Supervised Learning Approach.* IEEE CIACON. [doi:10.1109/CIACON65473.2025.11189545](https://doi.org/10.1109/CIACON65473.2025.11189545)
293
+ - Kasaraneni, C.K. et al. (2025). *Multi-modality Medical Image Fusion Using Machine Learning/Deep Learning.* Springer. [doi:10.1007/978-3-031-98728-1_16](https://doi.org/10.1007/978-3-031-98728-1_16)
294
+
295
+ ---
296
+
297
+ ## Related projects
298
+
299
+ - [`samplesheet-parser`](https://github.com/chaitanyakasaraneni/samplesheet-parser) — Format-agnostic Illumina SampleSheet parser (BCLConvert V2 + IEM V1)
300
+ - [`clinops`](https://github.com/chaitanyakasaraneni/clinops) — Clinical ML data quality library
301
+
302
+ ---
303
+
304
+ ## Repository structure
305
+
306
+ ```
307
+ cloudfit-core/
308
+ ├── README.md # first thing every visitor reads
309
+ ├── CITATION.cff # GitHub "Cite this repository" button — ORCID linked
310
+ ├── pyproject.toml # packaging, dependencies, PyPI metadata
311
+ ├── CONTRIBUTING.md # provider plugin interface guide
312
+ ├── LICENSE # Apache 2.0
313
+ ├── .gitignore
314
+
315
+ ├── cloudfit/
316
+ │ ├── __init__.py # exports rank, recommend, key models
317
+ │ ├── models.py # WorkloadProfile, MachineType, ScoredInstance (pydantic v2)
318
+ │ ├── scorer.py # rank(), score_instance(), weight matrix
319
+ │ ├── filter.py # hard_floor_check() — RAM, vCPU, GPU hard filters
320
+ │ ├── disk.py # compute_disk_tb() — dynamic disk sizing formula
321
+ │ ├── yaml_loader.py # from_yaml() — loads workload YAML schema
322
+ │ └── providers/
323
+ │ ├── __init__.py
324
+ │ └── base.py # abstract Provider class — plugin contract
325
+
326
+ └── tests/
327
+ ├── test_scorer.py # rank, scores, weight modes, hard floors
328
+ ├── test_disk.py # disk formula, CBCL vs BCL factor, sequencer profiles
329
+ └── test_yaml.py # from_yaml() loads profiles correctly
330
+ ```
331
+
332
+ ---
333
+
334
+ ## Contributing
335
+
336
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Issues and pull requests are welcome — especially provider plugins for new cloud platforms (Azure, Hetzner, Oracle Cloud).
337
+
338
+ ## License
339
+
340
+ Apache 2.0 — see [LICENSE](LICENSE).
341
+
342
+ ---
343
+
344
+ <sub>Author: <a href="https://ckasaraneni.com">Chaitanya Krishna Kasaraneni</a> &nbsp;·&nbsp;
345
+ <a href="https://scholar.google.com/citations?user=Y2S8D2UAAAAJ">Google Scholar</a> &nbsp;·&nbsp;
346
+ <a href="https://orcid.org/0000-0001-5792-1095">ORCID 0000-0001-5792-1095</a></sub>
@@ -0,0 +1,11 @@
1
+ cloudfit/__init__.py,sha256=0TQ8s8DHq5zLdEhTtyuhYWKf7i2pvUCibJdgTtUeyB4,953
2
+ cloudfit/disk.py,sha256=5n8vZkCCSCM7xCntGZ9hkDKHKl_ra-7WFdbvZ5mm6Uc,6584
3
+ cloudfit/filter.py,sha256=CGueCMItkfx29HXzuaAAaxHjUtEa1Evgz8aSCgmG-vU,2665
4
+ cloudfit/models.py,sha256=290zJuJGleTBQNbBXh_J7qAGO31lxZ2lZwbneW5WV44,2445
5
+ cloudfit/scorer.py,sha256=fOwiPvam4Ngju_5GXTUHPqmr51iXryt7FJIan_lF0mE,4622
6
+ cloudfit/yaml_loader.py,sha256=dYgQ6aoUVp71M1FV_4XQ08rVpAZafq8h2n5k8umEVRI,3645
7
+ cloudfit/providers/base.py,sha256=imDbyAePMFj5RVkSJ5LH1_eWGb-1qNWxm2N49Z5oPCc,741
8
+ cloudfit_core-0.1.0.dist-info/METADATA,sha256=LmjkZ97OEy7-BRRvdkoRlDVWijSBqrHgVT6oUdKaUDE,12405
9
+ cloudfit_core-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
10
+ cloudfit_core-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
+ cloudfit_core-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.