In this section
- Test Array Engine test · solar-electrical-topology-analysis-engine-text-based / tests/test_array_engine.py lines 1–381
- Test Array Topology test · solar-electrical-topology-analysis-engine-text-based / tests/test_array_topology.py lines 1–265
Test Array Engine
A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that checks Geometry Authority and Array Engine.
testsolar-electrical-topology-analysis-engine-text-based / tests/test_array_engine.py · lines 1–381 of 381 · Entry point
- What it does
- It tests its inputs. Defines 14 functions or classes, including comparison, test_reference_build_is_deterministic, test_every_reported_route_length_is_the_sum_of_stored_segments, test_strategy_comparison_preserves_common_authority_inputs, test_comparison_reports_length_and_loop_geometry_independently. Uses libraries math, pytest.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'array'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Downstream impact
- Used directly by 1 file: Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Defines `comparison`, `test_reference_build_is_deterministic`, `test_every_reported_route_length_is_the_sum_of_stored_segments` and 11 more.
- Why it matters
- Run by Build 025 Small Gates Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · tests · test
- Uses
- Geometry Authority (import), Array Engine (import), Array Routing (import), Array Topology (import), math, pytest
- Used by
- run by Build 025 Small Gates Workflow (workflow run)
- Produces
- comparison, test_reference_build_is_deterministic, test_every_reported_route_length_is_the_sum_of_stored_segments, test_strategy_comparison_preserves_common_authority_inputs, test_comparison_reports_length_and_loop_geometry_independently, test_moving_inverter_changes_only_dependent_home_geometry, test_home_run_segments_preserve_same_string_pole_identity, test_every_route_endpoint_is_an_authoritative_topology_node, test_reference_topology_contains_input_mppt_and_bus_terminals, test_installed_and_procurement_length_layers_are_receipted, test_installation_classification_is_carried_by_each_segment, test_parametric_small_rotated_table_uses_same_engine
- Defines here
- comparison, test_reference_build_is_deterministic, test_every_reported_route_length_is_the_sum_of_stored_segments, test_strategy_comparison_preserves_common_authority_inputs, test_comparison_reports_length_and_loop_geometry_independently, test_moving_inverter_changes_only_dependent_home_geometry, test_home_run_segments_preserve_same_string_pole_identity, test_every_route_endpoint_is_an_authoritative_topology_node, test_reference_topology_contains_input_mppt_and_bus_terminals, test_installed_and_procurement_length_layers_are_receipted, test_installation_classification_is_carried_by_each_segment, test_parametric_small_rotated_table_uses_same_engine, test_terminal_geometry_outside_module_envelope_is_rejected, test_terminal_geometry_provenance_is_part_of_routing_receipt
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 tests/test_array_engine.py:1-381 · blob 2d9518652ca75038f5be7bb50c678cc0de42c4c9 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
import math
import pytest
from geometry_authority import (
ModuleDimensions,
Point2D,
TableLayoutRequest,
generate_table_geometry,
)
from array_engine import (
build_complete_table,
compare_reference_24_by_30,
reference_24_by_30_build,
)
from array_routing import (
InstalledLengthPolicy,
InstallationMethod,
InverterPlacement,
ModuleTerminalLayout,
RoutingConfig,
)
from array_topology import NodeKind, WiringStrategy, uniform_equipment_profile
@pytest.fixture(scope="module")
def comparison():
return compare_reference_24_by_30()
def test_reference_build_is_deterministic() -> None:
first = reference_24_by_30_build()
second = reference_24_by_30_build()
assert first.receipt_hash == second.receipt_hash
assert first.routing.routing_hash == second.routing.routing_hash
assert (
first.string_allocation.assignment_hash
== second.string_allocation.assignment_hash
)
assert first.topology.topology_hash == second.topology.topology_hash
def test_every_reported_route_length_is_the_sum_of_stored_segments(
comparison,
) -> None:
for build in (comparison.sequential, comparison.leapfrog):
route_total = 0.0
for string in build.routing.strings:
routes = (
string.positive_route,
string.negative_route,
*string.interconnect_routes,
)
for route in routes:
segment_sum = math.fsum(
segment.geometric_length_m
for segment in route.segments
)
assert segment_sum == pytest.approx(
route.geometric_length_m,
abs=1e-8,
)
route_total += route.geometric_length_m
assert route_total == pytest.approx(
build.routing.metrics.total_circuit_conductor_length_m,
abs=1e-7,
)
def test_strategy_comparison_preserves_common_authority_inputs(
comparison,
) -> None:
assert (
comparison.sequential.geometry.geometry_hash
== comparison.leapfrog.geometry.geometry_hash
)
assert (
comparison.sequential.string_allocation.assignment_hash
== comparison.leapfrog.string_allocation.assignment_hash
)
assert (
comparison.sequential.input_allocation.allocation_hash
== comparison.leapfrog.input_allocation.allocation_hash
)
assert (
comparison.sequential.topology.topology_hash
!= comparison.leapfrog.topology.topology_hash
)
assert (
comparison.sequential.routing.routing_hash
!= comparison.leapfrog.routing.routing_hash
)
def test_comparison_reports_length_and_loop_geometry_independently(
comparison,
) -> None:
sequential = comparison.sequential.routing.metrics
leapfrog = comparison.leapfrog.routing.metrics
assert (
leapfrog.positive_conductor_length_m
< sequential.positive_conductor_length_m
)
assert (
leapfrog.inverter_home_run_length_m
< sequential.inverter_home_run_length_m
)
assert (
leapfrog.absolute_enclosed_loop_area_m2
< sequential.absolute_enclosed_loop_area_m2
)
assert (
leapfrog.series_interconnect_length_m
> sequential.series_interconnect_length_m
)
assert (
leapfrog.total_circuit_conductor_length_m
!= sequential.total_circuit_conductor_length_m
)
assert (
leapfrog.absolute_enclosed_loop_area_m2
>= abs(leapfrog.signed_loop_area_m2)
)
assert (
sequential.absolute_enclosed_loop_area_m2
>= abs(sequential.signed_loop_area_m2)
)
def test_moving_inverter_changes_only_dependent_home_geometry() -> None:
original = reference_24_by_30_build(
strategy=WiringStrategy.LEAPFROG,
inverter_position=Point2D(-5.0, 27.0),
)
moved = reference_24_by_30_build(
strategy=WiringStrategy.LEAPFROG,
inverter_position=Point2D(-15.0, 31.0),
)
assert original.geometry.geometry_hash == moved.geometry.geometry_hash
assert (
original.string_allocation.assignment_hash
== moved.string_allocation.assignment_hash
)
assert original.topology.topology_hash == moved.topology.topology_hash
assert (
original.input_allocation.allocation_hash
== moved.input_allocation.allocation_hash
)
assert original.routing.routing_hash != moved.routing.routing_hash
assert (
original.routing.metrics.inverter_home_run_length_m
!= moved.routing.metrics.inverter_home_run_length_m
)
for before, after in zip(
original.routing.strings,
moved.routing.strings,
):
assert [
route.route_hash for route in before.interconnect_routes
] == [
route.route_hash for route in after.interconnect_routes
]
assert (
before.positive_route.route_hash
!= after.positive_route.route_hash
)
assert (
before.negative_route.route_hash
!= after.negative_route.route_hash
)
def test_home_run_segments_preserve_same_string_pole_identity(
comparison,
) -> None:
for string in comparison.leapfrog.routing.strings:
assert string.positive_route.string_id == string.string_id
assert string.negative_route.string_id == string.string_id
assert all(
segment.string_id == string.string_id
for segment in string.positive_route.segments
)
assert all(
segment.string_id == string.string_id
for segment in string.negative_route.segments
)
assert {
segment.support_path_id
for segment in string.positive_route.segments
} == {
segment.support_path_id
for segment in string.negative_route.segments
}
def test_every_route_endpoint_is_an_authoritative_topology_node() -> None:
build = reference_24_by_30_build()
node_ids = {
node.node_id
for string in build.topology.strings
for node in string.nodes
} | {
node.node_id for node in build.topology.equipment_nodes
}
for string in build.routing.strings:
for route in (
string.positive_route,
string.negative_route,
*string.interconnect_routes,
):
assert route.from_node_id in node_ids
assert route.to_node_id in node_ids
def test_reference_topology_contains_input_mppt_and_bus_terminals() -> None:
build = reference_24_by_30_build()
kinds = [node.kind for node in build.topology.equipment_nodes]
assert kinds.count(NodeKind.PHYSICAL_INPUT_NEGATIVE) == 24
assert kinds.count(NodeKind.PHYSICAL_INPUT_POSITIVE) == 24
assert kinds.count(NodeKind.MPPT_INPUT) == 24
assert kinds.count(NodeKind.INVERTER_DC_BUS) == 2
assert len(build.topology.equipment_edges) == 120
def test_installed_and_procurement_length_layers_are_receipted() -> None:
policy = InstalledLengthPolicy(
connector_approach_m_per_route_end=0.10,
harness_offset_m_per_route=0.20,
bend_allowance_m_per_bend=0.05,
support_offset_m_per_segment=0.02,
service_loop_m_per_route=0.50,
termination_allowance_m_per_route_end=0.25,
construction_tolerance_fraction=0.03,
procurement_spare_fraction=0.02,
procurement_waste_fraction=0.01,
drum_length_m=500.0,
)
build = reference_24_by_30_build(
installed_length_policy=policy
)
receipt = build.installed_length
assert len(receipt.route_allowances) == 48
assert receipt.field_geometric_length_m == pytest.approx(
build.routing.metrics.inverter_home_run_length_m
)
assert receipt.factory_fitted_geometric_length_m == pytest.approx(
build.routing.metrics.series_interconnect_length_m
)
assert receipt.total_geometric_conductor_length_m == pytest.approx(
build.routing.metrics.total_circuit_conductor_length_m
)
assert (
receipt.installed_field_length_m
> receipt.field_geometric_length_m
)
assert (
receipt.procurement_pre_round_m
> receipt.installed_field_length_m
)
assert receipt.procurement_length_m % 500.0 == pytest.approx(0.0)
assert receipt.drum_rounding_m >= 0
assert all(
item.connector_approach_m == pytest.approx(0.20)
for item in receipt.route_allowances
)
assert all(
item.termination_allowance_m == pytest.approx(0.50)
for item in receipt.route_allowances
)
def test_installation_classification_is_carried_by_each_segment() -> None:
config = RoutingConfig(
home_run_installation_method=InstallationMethod.BURIED
)
build = reference_24_by_30_build(routing_config=config)
for string in build.routing.strings:
for route in (string.positive_route, string.negative_route):
assert all(segment.buried for segment in route.segments)
assert all(
not segment.screened for segment in route.segments
)
assert all(
segment.installation_method
is InstallationMethod.BURIED
for segment in route.segments
)
def test_parametric_small_rotated_table_uses_same_engine() -> None:
geometry = generate_table_geometry(
TableLayoutRequest(
table_id="ROTATED",
module_count=8,
rows=2,
columns=4,
module_dimensions=ModuleDimensions(
width_m=1.1,
height_m=2.0,
),
horizontal_gap_m=0.03,
vertical_gap_m=0.30,
origin=Point2D(100.0, -20.0),
rotation_deg=35.0,
)
)
profile = uniform_equipment_profile(
profile_id="SMALL-INPUTS",
inverter_id="INV-SMALL",
mppt_count=2,
inputs_per_mppt=1,
)
build = build_complete_table(
geometry,
string_count=2,
modules_per_string=4,
strategy=WiringStrategy.LEAPFROG,
equipment_profile=profile,
inverter=InverterPlacement(
"INV-SMALL",
Point2D(95.0, -16.0),
),
)
assert len(build.routing.strings) == 2
assert build.routing.metrics.total_circuit_conductor_length_m > 0
assert (
build.routing.metrics.absolute_enclosed_loop_area_m2
>= abs(build.routing.metrics.signed_loop_area_m2)
)
def test_terminal_geometry_outside_module_envelope_is_rejected() -> None:
invalid = RoutingConfig(
terminal_layout=ModuleTerminalLayout(
negative_offset_u_m=-10.0,
positive_offset_u_m=10.0,
source_reference="deliberately_invalid_test_fixture",
)
)
with pytest.raises(ValueError, match="outside module"):
reference_24_by_30_build(routing_config=invalid)
def test_terminal_geometry_provenance_is_part_of_routing_receipt() -> None:
assumed = reference_24_by_30_build(
routing_config=RoutingConfig(
terminal_layout=ModuleTerminalLayout(
evidence_class="assumed",
source_reference="source-A",
)
)
)
measured = reference_24_by_30_build(
routing_config=RoutingConfig(
terminal_layout=ModuleTerminalLayout(
evidence_class="measured",
source_reference="source-B",
)
)
)
assert assumed.geometry.geometry_hash == measured.geometry.geometry_hash
assert (
assumed.routing.strings[0].positive_route.route_hash
== measured.routing.strings[0].positive_route.route_hash
)
assert assumed.routing.routing_hash != measured.routing.routing_hash
assert assumed.receipt_hash != measured.receipt_hash
assert (
measured.routing.routing_config.terminal_layout.source_reference
== "source-B"
)Test Array Topology
A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that checks Geometry Authority and Array Topology.
testsolar-electrical-topology-analysis-engine-text-based / tests/test_array_topology.py · lines 1–265 of 265 · Entry point
- What it does
- It tests its inputs. Defines 8 functions or classes, including test_reference_allocation_is_a_complete_720_module_partition, test_allocation_hash_is_membership_deterministic, test_explicit_groups_must_be_complete_and_unique, test_leapfrog_order_is_one_complete_permutation, test_each_string_has_terminals_connectors_and_free_ends. Uses libraries pytest.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'array'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Downstream impact
- Used directly by 1 file: Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Defines `test_reference_allocation_is_a_complete_720_module_partition`, `test_allocation_hash_is_membership_deterministic`, `test_explicit_groups_must_be_complete_and_unique` and 5 more.
- Why it matters
- Run by Build 025 Small Gates Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · tests · test
- Uses
- Geometry Authority (import), Array Topology (import), pytest
- Used by
- run by Build 025 Small Gates Workflow (workflow run)
- Produces
- test_reference_allocation_is_a_complete_720_module_partition, test_allocation_hash_is_membership_deterministic, test_explicit_groups_must_be_complete_and_unique, test_leapfrog_order_is_one_complete_permutation, test_each_string_has_terminals_connectors_and_free_ends, test_strategy_changes_topology_not_physical_membership, test_physical_inputs_are_distinct_from_mppt_labels, test_duplicate_physical_input_assignment_fails_before_routing
- Defines here
- test_reference_allocation_is_a_complete_720_module_partition, test_allocation_hash_is_membership_deterministic, test_explicit_groups_must_be_complete_and_unique, test_leapfrog_order_is_one_complete_permutation, test_each_string_has_terminals_connectors_and_free_ends, test_strategy_changes_topology_not_physical_membership, test_physical_inputs_are_distinct_from_mppt_labels, test_duplicate_physical_input_assignment_fails_before_routing
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 tests/test_array_topology.py:1-265 · blob d099eac5c04727dcd9545ba27fb6dae5efe00d2c · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
import pytest
from geometry_authority import (
ModuleDimensions,
TableLayoutRequest,
generate_table_geometry,
reference_24_by_30_table,
)
from array_topology import (
EdgeKind,
NodeKind,
WiringStrategy,
allocate_physical_inputs,
allocate_strings,
build_table_topology,
electrical_module_order,
uniform_equipment_profile,
)
def test_reference_allocation_is_a_complete_720_module_partition() -> None:
geometry = reference_24_by_30_table()
receipt = allocate_strings(
geometry,
string_count=24,
modules_per_string=30,
)
assigned = [
module_id
for string in receipt.assignments
for module_id in string.physical_module_ids
]
assert len(receipt.assignments) == 24
assert all(
len(string.physical_module_ids) == 30
for string in receipt.assignments
)
assert len(assigned) == 720
assert len(set(assigned)) == 720
assert set(assigned) == {
placement.module_id
for placement in geometry.placements
}
assert receipt.assignments[0].physical_module_ids == tuple(
placement.module_id
for placement in geometry.placements[:30]
)
def test_allocation_hash_is_membership_deterministic() -> None:
geometry = reference_24_by_30_table()
first = allocate_strings(
geometry,
string_count=24,
modules_per_string=30,
)
second = allocate_strings(
geometry,
string_count=24,
modules_per_string=30,
)
assert first == second
assert first.assignment_hash == second.assignment_hash
def test_explicit_groups_must_be_complete_and_unique() -> None:
geometry = generate_table_geometry(
TableLayoutRequest(
table_id="SMALL",
module_count=8,
rows=2,
columns=4,
module_dimensions=ModuleDimensions(
width_m=1.0,
height_m=2.0,
),
)
)
ids = [placement.module_id for placement in geometry.placements]
with pytest.raises(
ValueError,
match="one-to-one partition",
):
allocate_strings(
geometry,
string_count=2,
modules_per_string=4,
explicit_module_groups=(
ids[:4],
(ids[3], ids[5], ids[6], ids[7]),
),
)
def test_leapfrog_order_is_one_complete_permutation() -> None:
ids = tuple(
f"M{index:02d}"
for index in range(1, 31)
)
result = electrical_module_order(
ids,
WiringStrategy.LEAPFROG,
)
assert result[:5] == (
"M01",
"M03",
"M05",
"M07",
"M09",
)
assert result[-5:] == (
"M10",
"M08",
"M06",
"M04",
"M02",
)
assert len(result) == 30
assert len(set(result)) == 30
assert set(result) == set(ids)
def test_each_string_has_terminals_connectors_and_free_ends() -> None:
allocation = allocate_strings(
reference_24_by_30_table(),
string_count=24,
modules_per_string=30,
)
receipt = build_table_topology(
allocation,
WiringStrategy.LEAPFROG,
)
string = receipt.strings[0]
membership = allocation.strings[0]
assert sum(
node.kind is NodeKind.MODULE_NEGATIVE_TERMINAL
for node in string.nodes
) == 30
assert sum(
node.kind is NodeKind.MODULE_POSITIVE_TERMINAL
for node in string.nodes
) == 30
assert sum(
node.kind is NodeKind.CONNECTOR
for node in string.nodes
) == 58
assert sum(
node.kind is NodeKind.STRING_NEGATIVE_FREE_END
for node in string.nodes
) == 1
assert sum(
node.kind is NodeKind.STRING_POSITIVE_FREE_END
for node in string.nodes
) == 1
assert sum(
edge.kind is EdgeKind.MODULE_INTERNAL
for edge in string.edges
) == 30
assert sum(
edge.kind is EdgeKind.CONNECTOR_MATE
for edge in string.edges
) == 29
assert (
string.free_negative_node_id
== membership.negative_free_terminal.terminal_id
)
assert (
string.free_positive_node_id
== membership.positive_free_terminal.terminal_id
)
def test_strategy_changes_topology_not_physical_membership() -> None:
allocation = allocate_strings(
reference_24_by_30_table(),
string_count=24,
modules_per_string=30,
)
sequential = build_table_topology(
allocation,
WiringStrategy.SEQUENTIAL,
)
leapfrog = build_table_topology(
allocation,
WiringStrategy.LEAPFROG,
)
assert sequential.assignment_hash == leapfrog.assignment_hash
assert sequential.topology_hash != leapfrog.topology_hash
assert (
sequential.strings[0].physical_module_ids
== leapfrog.strings[0].physical_module_ids
)
assert (
sequential.strings[0].electrical_module_ids
!= leapfrog.strings[0].electrical_module_ids
)
def test_physical_inputs_are_distinct_from_mppt_labels() -> None:
allocation = allocate_strings(
reference_24_by_30_table(),
string_count=24,
modules_per_string=30,
)
profile = uniform_equipment_profile(
mppt_count=12,
inputs_per_mppt=2,
)
receipt = allocate_physical_inputs(
allocation,
profile,
)
assert len(receipt.assignments) == 24
assert len({item.input_id for item in receipt.assignments}) == 24
assert len({item.mppt_id for item in receipt.assignments}) == 12
assert receipt.assignments[0].mppt_id == receipt.assignments[1].mppt_id
assert receipt.assignments[0].input_id != receipt.assignments[1].input_id
assert receipt.unused_input_ids == ()
assert receipt.unused_mppt_ids == ()
def test_duplicate_physical_input_assignment_fails_before_routing() -> None:
geometry = generate_table_geometry(
TableLayoutRequest(
table_id="INPUT-FAIL",
module_count=4,
rows=2,
columns=2,
module_dimensions=ModuleDimensions(
width_m=1.0,
height_m=2.0,
),
)
)
allocation = allocate_strings(
geometry,
string_count=2,
modules_per_string=2,
)
profile = uniform_equipment_profile(
mppt_count=1,
inputs_per_mppt=2,
)
first_input = profile.physical_inputs[0].input_id
explicit = {
assignment.string_id: first_input
for assignment in allocation.assignments
}
with pytest.raises(
ValueError,
match="exceeds its string capacity",
):
allocate_physical_inputs(
allocation,
profile,
explicit_input_by_string=explicit,
)