Requirements API¶
Requirements definition and verification classes.
Overview¶
from phased_array_systems.requirements import (
Requirement,
RequirementResult,
RequirementSet,
VerificationReport,
)
Classes¶
Requirement
dataclass
¶
Requirement(id: str, name: str, metric_key: str, op: ComparisonOp, value: float, units: str | None = None, severity: Severity = 'must')
A single requirement specification.
| ATTRIBUTE | DESCRIPTION |
|---|---|
id |
Unique identifier for the requirement (e.g., "REQ-001")
TYPE:
|
name |
Human-readable name
TYPE:
|
metric_key |
The key in the metrics dictionary to check
TYPE:
|
op |
Comparison operator
TYPE:
|
value |
Threshold value to compare against
TYPE:
|
units |
Optional units string for documentation
TYPE:
|
severity |
Importance level ("must", "should", "nice")
TYPE:
|
check
¶
Check if the actual value satisfies this requirement.
| PARAMETER | DESCRIPTION |
|---|---|
actual_value
|
The measured/computed value to check
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if requirement is satisfied, False otherwise |
Source code in src/phased_array_systems/requirements/core.py
compute_margin
¶
Compute the margin to the requirement threshold.
Positive margin means the requirement is satisfied with room to spare. Negative margin means the requirement is not met.
| PARAMETER | DESCRIPTION |
|---|---|
actual_value
|
The measured/computed value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Margin value (interpretation depends on operator) |
Source code in src/phased_array_systems/requirements/core.py
RequirementResult
dataclass
¶
RequirementResult(requirement: Requirement, actual_value: float | None, passes: bool, margin: float | None, error: str | None = None)
Result of checking a single requirement.
| ATTRIBUTE | DESCRIPTION |
|---|---|
requirement |
The requirement that was checked
TYPE:
|
actual_value |
The actual value from metrics (None if metric missing)
TYPE:
|
passes |
Whether the requirement passed
TYPE:
|
margin |
Margin to the threshold
TYPE:
|
error |
Error message if metric was missing or check failed
TYPE:
|
RequirementSet
dataclass
¶
RequirementSet(requirements: list[Requirement] = list(), name: str | None = None)
A collection of requirements with verification capabilities.
| ATTRIBUTE | DESCRIPTION |
|---|---|
requirements |
List of requirements
TYPE:
|
name |
Optional name for the requirement set
TYPE:
|
add
¶
add(requirement: Requirement) -> None
verify
¶
verify(metrics: MetricsDict) -> VerificationReport
Verify all requirements against provided metrics.
| PARAMETER | DESCRIPTION |
|---|---|
metrics
|
Dictionary of metric_name -> value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
VerificationReport
|
VerificationReport with pass/fail status and margins |
Source code in src/phased_array_systems/requirements/core.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
get_by_id
¶
get_by_id(req_id: str) -> Requirement | None
VerificationReport
dataclass
¶
VerificationReport(passes: bool, results: list[RequirementResult], failed_ids: list[str], must_pass_count: int = 0, must_total_count: int = 0, should_pass_count: int = 0, should_total_count: int = 0)
Complete verification report for a set of requirements.
| ATTRIBUTE | DESCRIPTION |
|---|---|
passes |
True if ALL 'must' requirements pass
TYPE:
|
results |
List of individual requirement results
TYPE:
|
failed_ids |
List of requirement IDs that failed
TYPE:
|
must_pass_count |
Number of must requirements that passed
TYPE:
|
must_total_count |
Total number of must requirements
TYPE:
|
should_pass_count |
Number of should requirements that passed
TYPE:
|
should_total_count |
Total number of should requirements
TYPE:
|
to_dict
¶
Convert report to dictionary for serialization.
Source code in src/phased_array_systems/requirements/core.py
Usage Examples¶
Defining Requirements¶
from phased_array_systems.requirements import Requirement, RequirementSet
# Create individual requirements
req1 = Requirement(
id="REQ-001",
name="Minimum EIRP",
metric_key="eirp_dbw",
op=">=",
value=40.0,
units="dBW",
severity="must",
)
req2 = Requirement(
id="REQ-002",
name="Positive Link Margin",
metric_key="link_margin_db",
op=">=",
value=0.0,
severity="must",
)
# Create requirement set
requirements = RequirementSet(
requirements=[req1, req2],
name="Communications Requirements",
)
Verifying Requirements¶
from phased_array_systems.evaluate import evaluate_case
metrics = evaluate_case(arch, scenario)
report = requirements.verify(metrics)
# Check overall status
print(f"Overall: {'PASS' if report.passes else 'FAIL'}")
print(f"Must: {report.must_pass_count}/{report.must_total_count}")
# Check individual requirements
for result in report.results:
status = "PASS" if result.passes else "FAIL"
print(f"{result.requirement.id}: {status} (margin: {result.margin:.1f})")
Checking Individual Requirements¶
req = Requirement("TEST", "Test", "value", ">=", 10.0)
# Check if value passes
print(req.check(15.0)) # True
print(req.check(5.0)) # False
# Compute margin
print(req.compute_margin(15.0)) # 5.0
print(req.compute_margin(5.0)) # -5.0
Serializing Reports¶
report = requirements.verify(metrics)
report_dict = report.to_dict()
# Contains structured verification data
import json
print(json.dumps(report_dict, indent=2))
Type Aliases¶
from phased_array_systems.types import ComparisonOp, Severity
# ComparisonOp = Literal[">=", "<=", ">", "<", "=="]
# Severity = Literal["must", "should", "nice"]