gridstate 2.12.0__tar.gz → 2.13.0__tar.gz
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.
- {gridstate-2.12.0 → gridstate-2.13.0}/PKG-INFO +1 -1
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/_version.py +3 -3
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algorithms/wls.py +138 -2
- gridstate-2.13.0/gridstate/algorithms/wls_box.py +360 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/api.py +118 -24
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/config.py +47 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/passes.py +7 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/preparation.py +2 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/preprocessing/pseudo_measurements.py +54 -4
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/result.py +8 -3
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/supernodes.py +5 -3
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate.egg-info/PKG-INFO +1 -1
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate.egg-info/SOURCES.txt +3 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate.egg-info/scm_file_list.json +3 -0
- gridstate-2.13.0/gridstate.egg-info/scm_version.json +8 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_ipm_injection_roles.py +30 -0
- gridstate-2.13.0/tests/test_pseudo_transit_tight.py +169 -0
- gridstate-2.13.0/tests/test_wls_node_box.py +292 -0
- gridstate-2.12.0/gridstate.egg-info/scm_version.json +0 -8
- {gridstate-2.12.0 → gridstate-2.13.0}/.github/workflows/ci.yml +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/.github/workflows/release.yml +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/.gitignore +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/.pre-commit-config.yaml +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/CHANGELOG.md +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/LICENSE +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/Makefile +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/README.md +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/build_cython.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/__pyinstaller/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/__pyinstaller/hook-gridstate.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/_arrays.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/adapters/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/adapters/from_pandapower.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algebra/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algebra/_selinv_kernels.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algebra/base.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algebra/estimators.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algebra/jacobian_pattern.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algebra/normalized_residuals.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algorithms/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algorithms/_gram_numba.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algorithms/ipm.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algorithms/ipm_pd.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algorithms/kkt_solver.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/algorithms/status.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/bad_data_repass.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/bounds.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/constants.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/_legacy.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/containers.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/derived.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/derived_tables.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/serialize.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/tables.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/validate.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/contract/version.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/ipm_hints.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/load_characteristics.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/losses.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/measurement_ids.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/context.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/manifest.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/orchestration.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/runner.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/pipeline/steps.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/post_processing.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/preprocessing/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/preprocessing/_scan.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/preprocessing/ipm_setup.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/preprocessing/meas_rows.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/preprocessing/mirror_voltage.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/preprocessing/node_props.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/py.typed +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/quality_summary.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/resolve_pass.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/runtime.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/shunt_sanity.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/solution_hints.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/state.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/_filters.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/apply_resolved.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/generators.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/kinds.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/load_only_injection.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/loss_filter.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/measurements.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/noise.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/on_line.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/quality.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/rpn.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/shunts.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/sigma_floor.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/units.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/voltage_filter.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/telemetry/voltage_nominal.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/topology.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/units.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/utils.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/v_mirror.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/v_refine.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/validation/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/validation/_diagnostics.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/validation/bad_data.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/validation/chi2_test.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/validation/observability.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/working.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/ybus.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate/z_vector.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate.egg-info/dependency_links.txt +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate.egg-info/entry_points.txt +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate.egg-info/requires.txt +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/gridstate.egg-info/top_level.txt +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/pyproject.toml +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/setup.cfg +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/__init__.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/_golden.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/conftest.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_adapters_lazy_import.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_aggregate_generators.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_algebra_base.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_anti_overshoot.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_arrays_helpers.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_bad_data.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_bad_data_repass.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_bounds.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_boxed_balance.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_breaker_reactance.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_chain_mirror.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_contract.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_contract_edge_cases.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_contract_runtime.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case118.json +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case118.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case118_degraded.json +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case118_degraded.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case14.json +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case14.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case14_degraded.json +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case14_degraded.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case30.json +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case30.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case30_degraded.json +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/case30_degraded.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/golden/manifest.json +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/ieee/case118.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/ieee/case118_truth.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/ieee/case14.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/ieee/case14_truth.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/ieee/case30.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_data/ieee/case30_truth.npz +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_derived_tables.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_enum_codes.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_external_sigma2.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_flow_sigma_floor.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_from_pandapower.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_generator_shunt_kernels.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_golden.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_gram_numba.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_ieee_cases.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_injection_split.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_ipm.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_ipm_balance_modes.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_ipm_hints.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_ipm_integration.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_ipm_pd.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_jacobian_pattern.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_kkt_solver.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_load_characteristic_segments.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_load_only_injection.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_losses_breakdown.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_losses_q_convention.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_losses_trafo_classification.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_materialize_kernel.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_measurement_filter_kernels.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_measurement_ids.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_mirror_voltage_kernel.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_near_critical_ranking.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_neutral_wording.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_noise_model.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_normalized_residuals.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_numpy_only_runtime.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_observability.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_on_line_kernel.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_perf_synthetic_network.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pipeline.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pipeline_config_validation.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pipeline_idempotent.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pipeline_invariant_errors.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pipeline_step_order.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pipeline_warm_start.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pipeline_working_layer.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_post_processing.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_preparation_steps.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_prepare_network.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pseudo_unknown_load.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pseudo_v_scope.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_pseudo_v_unobservable.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_quality_summary_paths.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_reconcile_balance.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_refine_merge.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_resolve_pass.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_result_quality_summary.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_rn_selected_inversion.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_serialize_npz.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_shunt_sanity.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_solution_hints.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_solve_status.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_state.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_state_range.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_supernodes.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_telemetry_apply_kernel.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_telemetry_bounds.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_telemetry_physics_kernels.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_tm_code_quality.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_topology_kernels.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_topology_port.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_transformer_from_shunt.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_units.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_units_array_kernels.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_v_mirror.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_v_refine.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_variance_charging.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_version.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_voltage_calibration_gen_nodes.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_voltage_range_filter_fallback.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_wls.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_wls_robustness.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_working_container.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_ybus.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tests/test_z_vector.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tools/gen_ieee_fixtures.py +0 -0
- {gridstate-2.12.0 → gridstate-2.13.0}/tools/golden.py +0 -0
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '2.
|
|
22
|
-
__version_tuple__ = version_tuple = (2,
|
|
21
|
+
__version__ = version = '2.13.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (2, 13, 0)
|
|
23
23
|
|
|
24
|
-
__commit_id__ = commit_id = '
|
|
24
|
+
__commit_id__ = commit_id = 'g795002762'
|
|
@@ -54,11 +54,13 @@ from gridstate.algebra.base import BaseAlgebra
|
|
|
54
54
|
from gridstate.algebra.estimators import HuberReweighter, build_branch_pq_huber_mask
|
|
55
55
|
from gridstate.algorithms.kkt_solver import KKTSolver
|
|
56
56
|
from gridstate.algorithms.status import SolveStatus
|
|
57
|
+
from gridstate.algorithms.wls_box import BoxActiveSet, BoxWarmStart
|
|
57
58
|
from gridstate.state import unpack
|
|
58
59
|
from gridstate.utils import floored_sigma2, scale_csr_rows, sparse_diag
|
|
59
60
|
|
|
60
61
|
|
|
61
62
|
if TYPE_CHECKING:
|
|
63
|
+
from gridstate.algorithms.wls_box import NodeBox
|
|
62
64
|
from gridstate.state import StateLayout
|
|
63
65
|
from gridstate.units import NetworkPU
|
|
64
66
|
from gridstate.z_vector import MeasurementIndex
|
|
@@ -83,6 +85,12 @@ class WLSResult:
|
|
|
83
85
|
``KKT``, ``TR_COLLAPSED``, ``MAX_ITER``, ``STALLED``,
|
|
84
86
|
``DIVERGED`` or ``ERROR``. ``success`` keeps the legacy rule
|
|
85
87
|
(``True`` for both ``KKT`` and ``TR_COLLAPSED``).
|
|
88
|
+
box_stats: node box counters (``node_box`` given):
|
|
89
|
+
``rows``, ``stage``, ``active``, ``activated``, ``released``;
|
|
90
|
+
``None`` without boxes.
|
|
91
|
+
box_warm_start: the final active set of the node boxes, the start of
|
|
92
|
+
a warm re-solve (``box_warm_start`` of :func:`solve_wls`);
|
|
93
|
+
``None`` without boxes or when they never started.
|
|
86
94
|
"""
|
|
87
95
|
|
|
88
96
|
x: np.ndarray
|
|
@@ -90,6 +98,8 @@ class WLSResult:
|
|
|
90
98
|
iterations: int
|
|
91
99
|
objective: float
|
|
92
100
|
solve_status: SolveStatus = SolveStatus.ERROR
|
|
101
|
+
box_stats: dict[str, int] | None = None
|
|
102
|
+
box_warm_start: BoxWarmStart | None = None
|
|
93
103
|
|
|
94
104
|
|
|
95
105
|
def _solve_damped(
|
|
@@ -242,6 +252,13 @@ def solve_wls(
|
|
|
242
252
|
huber_adaptive_k: float = 6.0,
|
|
243
253
|
huber_warmup_iters: int = 5,
|
|
244
254
|
kkt_solver: KKTSolver | None = None,
|
|
255
|
+
node_box: NodeBox | None = None,
|
|
256
|
+
box_sigma2_schedule: tuple[float, ...] = (1e-2, 1e-4, 1e-6),
|
|
257
|
+
box_tol: float = 1e-4,
|
|
258
|
+
box_max_releases: int = 2,
|
|
259
|
+
box_max_corrections: int = 3,
|
|
260
|
+
box_round_tolerance: float | None = None,
|
|
261
|
+
box_warm_start: BoxWarmStart | None = None,
|
|
245
262
|
) -> WLSResult:
|
|
246
263
|
"""Run trust-region Gauss-Newton WLS (optionally SHGM-IRLS).
|
|
247
264
|
|
|
@@ -278,6 +295,31 @@ def solve_wls(
|
|
|
278
295
|
kkt_solver: solver of the normal-equation systems that reuses the
|
|
279
296
|
symbolic factorization (see ``gridstate.algorithms.kkt_solver``).
|
|
280
297
|
``None`` — scipy spsolve (the former behaviour, bit for bit).
|
|
298
|
+
node_box: node boxes of the injections and voltages
|
|
299
|
+
(:mod:`gridstate.algorithms.wls_box`), enforced by an active set of bound rows once the unconstrained
|
|
300
|
+
solve has converged; ``None`` (default) — no boxes. A solution
|
|
301
|
+
inside every box is the plain WLS bit for bit.
|
|
302
|
+
box_sigma2_schedule: variances (p.u.²) of the bound rows by stage,
|
|
303
|
+
loose to tight; the solve moves to the next stage when the
|
|
304
|
+
current one has converged with an unchanged active set; in the
|
|
305
|
+
last one the targets of the pinned rows are shifted until each
|
|
306
|
+
holds its bound to ``box_tol``.
|
|
307
|
+
box_tol: a quantity outside its box by more than this (p.u.) pins the row.
|
|
308
|
+
box_max_releases: times a pinned row may be released (at converged
|
|
309
|
+
points, when the solution pulls it inside its box); then it stays
|
|
310
|
+
pinned.
|
|
311
|
+
box_max_corrections: times the target of a pinned row may be shifted
|
|
312
|
+
in the last stage (where the boxes cannot all hold, the shift
|
|
313
|
+
would grow without bound).
|
|
314
|
+
box_round_tolerance: ``max|ΔE|`` at which a round of the active set
|
|
315
|
+
counts as converged for the next set change (``None`` —
|
|
316
|
+
``tolerance``). The rounds before the last only steer the set, so
|
|
317
|
+
a looser value saves iterations; the solve still ends at
|
|
318
|
+
``tolerance``.
|
|
319
|
+
box_warm_start: the active set of a previous solve of the same
|
|
320
|
+
network (``WLSResult.box_warm_start``): the solve starts with it
|
|
321
|
+
in the last stage instead of converging without boxes first.
|
|
322
|
+
Ignored when its rows differ from ``node_box``.
|
|
281
323
|
|
|
282
324
|
Returns:
|
|
283
325
|
:class:`WLSResult` (``x``, ``success``, ``iterations``, ``objective``).
|
|
@@ -291,6 +333,18 @@ def solve_wls(
|
|
|
291
333
|
|
|
292
334
|
algebra = BaseAlgebra(ybus, yf, yt, meas_index, layout, network_pu)
|
|
293
335
|
solver = kkt_solver if kkt_solver is not None else KKTSolver("scipy")
|
|
336
|
+
box_set = (
|
|
337
|
+
BoxActiveSet(
|
|
338
|
+
node_box,
|
|
339
|
+
BaseAlgebra(ybus, yf, yt, node_box.meas_index(), layout, network_pu),
|
|
340
|
+
sigma2_schedule=box_sigma2_schedule,
|
|
341
|
+
tol=box_tol,
|
|
342
|
+
max_releases=box_max_releases,
|
|
343
|
+
max_corrections=box_max_corrections,
|
|
344
|
+
)
|
|
345
|
+
if node_box is not None and len(node_box) > 0
|
|
346
|
+
else None
|
|
347
|
+
)
|
|
294
348
|
|
|
295
349
|
# σ² with regularization; then R⁻¹ as a sparse diagonal.
|
|
296
350
|
sigma2 = floored_sigma2(r_matrix.diagonal())
|
|
@@ -379,7 +433,58 @@ def solve_wls(
|
|
|
379
433
|
stop_status: SolveStatus | None = None
|
|
380
434
|
last_step_plain_gn = False
|
|
381
435
|
|
|
382
|
-
|
|
436
|
+
# Node boxes: the bound rows join after the unconstrained solve converged
|
|
437
|
+
# (see gridstate.algorithms.wls_box), or from the start with the set of a
|
|
438
|
+
# previous solve. Every round of the active set (a new stage or a changed
|
|
439
|
+
# set at a converged point) gets 2 × max_iterations, the whole solve at
|
|
440
|
+
# most (1 + 2 · stages) × max_iterations. A round counts as converged at
|
|
441
|
+
# box_round_tolerance; once the set has settled, the solve goes on to
|
|
442
|
+
# tolerance.
|
|
443
|
+
it_limit = max_iterations
|
|
444
|
+
it_cap = max_iterations * (1 + 2 * len(box_sigma2_schedule))
|
|
445
|
+
h_box_cur = np.zeros(0)
|
|
446
|
+
stop_tol = tolerance
|
|
447
|
+
if box_set is not None:
|
|
448
|
+
stop_tol = max(tolerance, box_round_tolerance or tolerance)
|
|
449
|
+
if box_warm_start is not None:
|
|
450
|
+
h_box_cur = box_set.injections(v, delta)
|
|
451
|
+
if box_set.resume(box_warm_start, h_box_cur):
|
|
452
|
+
objective = float(r_cur @ (r_inv @ r_cur)) + box_set.penalty(h_box_cur)
|
|
453
|
+
|
|
454
|
+
def _box_next() -> bool:
|
|
455
|
+
"""Converged: start the boxes, re-solve with a changed set, tighten or stop."""
|
|
456
|
+
nonlocal current_error, it_limit, objective, h_box_cur, tr_radius, lam, stop_tol
|
|
457
|
+
if box_set is None or current_error > stop_tol or cur_it >= it_cap:
|
|
458
|
+
return False
|
|
459
|
+
h_box_cur = box_set.injections(v, delta)
|
|
460
|
+
if box_set.stage == 0:
|
|
461
|
+
changed = box_set.start(h_box_cur)
|
|
462
|
+
else:
|
|
463
|
+
changed = box_set.pin(h_box_cur) | box_set.release(h_box_cur)
|
|
464
|
+
if not changed:
|
|
465
|
+
if not box_set.last_stage:
|
|
466
|
+
box_set.advance()
|
|
467
|
+
changed = True
|
|
468
|
+
else:
|
|
469
|
+
changed = box_set.correct(h_box_cur)
|
|
470
|
+
if not changed:
|
|
471
|
+
if current_error <= tolerance:
|
|
472
|
+
return False
|
|
473
|
+
# The set has settled at a round tolerance: finish at the solve one.
|
|
474
|
+
stop_tol = tolerance
|
|
475
|
+
if box_set.stage > 0:
|
|
476
|
+
it_limit = min(cur_it + 2 * max_iterations, it_cap)
|
|
477
|
+
return True
|
|
478
|
+
objective = float(r_cur @ (r_inv @ r_cur)) + box_set.penalty(h_box_cur)
|
|
479
|
+
current_error = float("inf")
|
|
480
|
+
it_limit = min(cur_it + 2 * max_iterations, it_cap)
|
|
481
|
+
# A new problem: the trust region and the damper of the previous one
|
|
482
|
+
# (possibly collapsed) would freeze the iterate at its old point.
|
|
483
|
+
tr_radius = tr_radius_max
|
|
484
|
+
lam = 0.0
|
|
485
|
+
return True
|
|
486
|
+
|
|
487
|
+
while (current_error > stop_tol and cur_it < it_limit) or _box_next():
|
|
383
488
|
# SHGM-IRLS: recompute weights from the last residual. Warmup
|
|
384
489
|
# iterations run as pure WLS — flat-start residuals are not
|
|
385
490
|
# informative for outlier detection.
|
|
@@ -387,12 +492,19 @@ def solve_wls(
|
|
|
387
492
|
r_inv_diag = r_inv_diag_base * reweighter.weights(r_cur)
|
|
388
493
|
r_inv = sparse_diag(r_inv_diag)
|
|
389
494
|
objective = float(r_cur @ (r_inv @ r_cur))
|
|
495
|
+
if box_set is not None and box_set.stage > 0:
|
|
496
|
+
objective += box_set.penalty(h_box_cur)
|
|
390
497
|
|
|
391
498
|
H = algebra.evaluate_jacobian(v, delta)
|
|
392
499
|
# H.T @ R^-1 with diagonal R^-1 == row-scaling H then transpose.
|
|
393
500
|
Ht_Rinv = scale_csr_rows(H, r_inv_diag).T
|
|
394
|
-
G = (Ht_Rinv @ H).tocsc()
|
|
395
501
|
rhs = np.asarray(Ht_Rinv @ r_cur, dtype=np.float64).ravel()
|
|
502
|
+
if box_set is not None and box_set.any_active():
|
|
503
|
+
G_box, rhs_box = box_set.normal_terms(v, delta, h_box_cur)
|
|
504
|
+
G = (Ht_Rinv @ H + G_box).tocsc()
|
|
505
|
+
rhs = rhs + rhs_box
|
|
506
|
+
else:
|
|
507
|
+
G = (Ht_Rinv @ H).tocsc()
|
|
396
508
|
diag_G = G.diagonal()
|
|
397
509
|
if not np.any(diag_G != 0):
|
|
398
510
|
logger.warning("Zero diagonal of G at iteration %d — stopping", cur_it)
|
|
@@ -405,6 +517,7 @@ def solve_wls(
|
|
|
405
517
|
h_trial = h_cur
|
|
406
518
|
r_trial = r_cur
|
|
407
519
|
obj_trial = objective
|
|
520
|
+
h_box_trial = h_box_cur
|
|
408
521
|
for inner in range(inner_max):
|
|
409
522
|
tr_attempt = tr_radius
|
|
410
523
|
d_E, step_inf, lam_used, solve_ok = _solve_in_trust_region(
|
|
@@ -436,6 +549,7 @@ def solve_wls(
|
|
|
436
549
|
obj_trial = objective
|
|
437
550
|
h_trial = h_cur
|
|
438
551
|
r_trial = r_cur
|
|
552
|
+
h_box_trial = h_box_cur
|
|
439
553
|
break
|
|
440
554
|
|
|
441
555
|
E_trial = E + d_E
|
|
@@ -443,6 +557,9 @@ def solve_wls(
|
|
|
443
557
|
h_trial = algebra.evaluate_h(v_t, delta_t)
|
|
444
558
|
r_trial = z - h_trial
|
|
445
559
|
obj_trial = float(r_trial @ (r_inv @ r_trial))
|
|
560
|
+
if box_set is not None and box_set.stage > 0:
|
|
561
|
+
h_box_trial = box_set.injections(v_t, delta_t)
|
|
562
|
+
obj_trial += box_set.penalty(h_box_trial)
|
|
446
563
|
if not np.isfinite(obj_trial) or not np.all(np.isfinite(h_trial)):
|
|
447
564
|
# The trial point gave NaN/Inf in h(E) or J — a non-physical state.
|
|
448
565
|
# We abort: it is either a bad problem or a bad step
|
|
@@ -563,11 +680,28 @@ def solve_wls(
|
|
|
563
680
|
objective = obj_trial
|
|
564
681
|
current_error = applied_step
|
|
565
682
|
cur_it += 1
|
|
683
|
+
if box_set is not None and box_set.stage > 0:
|
|
684
|
+
# Pin at the new point; the objective follows the new set.
|
|
685
|
+
h_box_cur = h_box_trial
|
|
686
|
+
if box_set.pin(h_box_cur):
|
|
687
|
+
objective = float(r_cur @ (r_inv @ r_cur)) + box_set.penalty(h_box_cur)
|
|
566
688
|
|
|
567
689
|
if diverged:
|
|
568
690
|
break
|
|
569
691
|
|
|
570
692
|
success = current_error <= tolerance and not diverged
|
|
693
|
+
box_stats: dict[str, int] | None = None
|
|
694
|
+
if box_set is not None:
|
|
695
|
+
# Report the data objective: the bound rows are constraints, not data.
|
|
696
|
+
if box_set.stage > 0:
|
|
697
|
+
objective -= box_set.penalty(h_box_cur)
|
|
698
|
+
box_stats = {
|
|
699
|
+
"rows": len(box_set.box),
|
|
700
|
+
"stage": box_set.stage,
|
|
701
|
+
"active": box_set.n_active(),
|
|
702
|
+
"activated": box_set.activated,
|
|
703
|
+
"released": box_set.released,
|
|
704
|
+
}
|
|
571
705
|
if stop_status is not None:
|
|
572
706
|
solve_status = stop_status
|
|
573
707
|
elif success:
|
|
@@ -594,4 +728,6 @@ def solve_wls(
|
|
|
594
728
|
iterations=cur_it,
|
|
595
729
|
objective=objective,
|
|
596
730
|
solve_status=solve_status,
|
|
731
|
+
box_stats=box_stats,
|
|
732
|
+
box_warm_start=None if box_set is None else box_set.warm_start(),
|
|
597
733
|
)
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"""Node boxes for WLS: an active set of bound rows.
|
|
2
|
+
|
|
3
|
+
A node can inject only what its generation and load allow: the P injection
|
|
4
|
+
lies in ``[Σpg_min − pn_max, Σpg_max − pn_min]`` (generation part when
|
|
5
|
+
``exist_gen``, load part when ``exist_load``), Q likewise; a transit node
|
|
6
|
+
(neither) injects exactly zero. These are hard limits of the data. Gauss-Newton
|
|
7
|
+
WLS has no inequalities, so they are enforced with an active set of bound rows:
|
|
8
|
+
|
|
9
|
+
* a bound row measures the node injection (the same ``h`` as an injection
|
|
10
|
+
measurement) with the violated bound as its value;
|
|
11
|
+
* it enters the normal equations only while active: a node whose injection
|
|
12
|
+
leaves its box is pinned to the bound it crossed;
|
|
13
|
+
* rows are pinned as soon as an iteration leaves their box; a pinned row is
|
|
14
|
+
released only at a converged point, when the solution pulls it back inside
|
|
15
|
+
(the sign of its multiplier turned), at most ``max_releases`` times; the
|
|
16
|
+
release only moves the node inside, never out. A point box (a transit node)
|
|
17
|
+
is never released;
|
|
18
|
+
* the weight of the bound rows tightens in stages (``sigma2_schedule``, like
|
|
19
|
+
the barrier parameter of an IPM): an early tight bound on a far-off state
|
|
20
|
+
would steer the iterations badly;
|
|
21
|
+
* in the last stage the target of a pinned row is shifted by what the
|
|
22
|
+
injection still misses (the method of multipliers), so the bound holds to
|
|
23
|
+
``tol`` without a heavier weight. A row is shifted at most
|
|
24
|
+
``max_corrections`` times: where the boxes cannot all hold together (line
|
|
25
|
+
charging in a pocket of nodes that may not take Q), the shift would grow
|
|
26
|
+
without bound and drag the solution along.
|
|
27
|
+
|
|
28
|
+
The same rows can bound the node voltage (:func:`voltage_boxes`): a load
|
|
29
|
+
pinned at its maximum on a weak feeder can otherwise only be served on the
|
|
30
|
+
collapsed branch of the voltage solution.
|
|
31
|
+
|
|
32
|
+
The set starts once the unconstrained WLS has converged; a solve whose
|
|
33
|
+
solution respects every box is therefore bit for bit the plain WLS. A warm
|
|
34
|
+
re-solve of the same network (the passes after bad data, refinement) starts
|
|
35
|
+
from the set of the previous solve (:class:`BoxWarmStart`) in the last stage.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from __future__ import annotations
|
|
39
|
+
|
|
40
|
+
from dataclasses import dataclass
|
|
41
|
+
from typing import TYPE_CHECKING
|
|
42
|
+
|
|
43
|
+
import numpy as np
|
|
44
|
+
from scipy.sparse import csr_matrix
|
|
45
|
+
|
|
46
|
+
from gridstate.bounds import is_reactive_only_generation, resolve_bounds
|
|
47
|
+
from gridstate.utils import scale_csr_rows
|
|
48
|
+
from gridstate.z_vector import (
|
|
49
|
+
KIND_POWER_INJECTION_P,
|
|
50
|
+
KIND_POWER_INJECTION_Q,
|
|
51
|
+
KIND_VOLTAGE,
|
|
52
|
+
MeasurementIndex,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if TYPE_CHECKING:
|
|
57
|
+
from gridstate.algebra.base import BaseAlgebra
|
|
58
|
+
from gridstate.units import NetworkPU
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True)
|
|
62
|
+
class NodeBox:
|
|
63
|
+
"""Bounds of node quantities, one row per (node, quantity).
|
|
64
|
+
|
|
65
|
+
Attributes:
|
|
66
|
+
bus_pos: positional bus index (``NetworkPU.bus_ids`` order).
|
|
67
|
+
kind: ``KIND_POWER_INJECTION_P`` / ``KIND_POWER_INJECTION_Q``
|
|
68
|
+
(generation-positive) or ``KIND_VOLTAGE``.
|
|
69
|
+
lo, hi: bounds in p.u.; an unset side is ``±inf``.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
bus_pos: np.ndarray
|
|
73
|
+
kind: np.ndarray
|
|
74
|
+
lo: np.ndarray
|
|
75
|
+
hi: np.ndarray
|
|
76
|
+
|
|
77
|
+
def __len__(self) -> int:
|
|
78
|
+
return int(self.bus_pos.shape[0])
|
|
79
|
+
|
|
80
|
+
def concat(self, other: NodeBox) -> NodeBox:
|
|
81
|
+
"""Rows of ``self`` followed by the rows of ``other``."""
|
|
82
|
+
return NodeBox(
|
|
83
|
+
bus_pos=np.concatenate([self.bus_pos, other.bus_pos]),
|
|
84
|
+
kind=np.concatenate([self.kind, other.kind]),
|
|
85
|
+
lo=np.concatenate([self.lo, other.lo]),
|
|
86
|
+
hi=np.concatenate([self.hi, other.hi]),
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
def meas_index(self) -> MeasurementIndex:
|
|
90
|
+
"""Measurement rows of the node injections the bounds apply to."""
|
|
91
|
+
n = len(self)
|
|
92
|
+
return MeasurementIndex(
|
|
93
|
+
kind=self.kind.astype(np.int64),
|
|
94
|
+
object_kind=np.zeros(n, dtype=np.int64),
|
|
95
|
+
object_pos=self.bus_pos.astype(np.int64),
|
|
96
|
+
branch_side=np.full(n, -1, dtype=np.int64),
|
|
97
|
+
meas_id=np.full(n, -1, dtype=np.int64),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@dataclass(frozen=True)
|
|
102
|
+
class BoxWarmStart:
|
|
103
|
+
"""Active set of a finished solve, the start of a warm re-solve.
|
|
104
|
+
|
|
105
|
+
Attributes:
|
|
106
|
+
bus_pos, kind: rows of the box it belongs to (a box with other rows
|
|
107
|
+
ignores it).
|
|
108
|
+
state: ``-1`` / ``0`` / ``+1`` per row (see :class:`BoxActiveSet`).
|
|
109
|
+
shift: target shifts of the pinned rows (p.u.).
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
bus_pos: np.ndarray
|
|
113
|
+
kind: np.ndarray
|
|
114
|
+
state: np.ndarray
|
|
115
|
+
shift: np.ndarray
|
|
116
|
+
|
|
117
|
+
def fits(self, box: NodeBox) -> bool:
|
|
118
|
+
"""Same rows as ``box``."""
|
|
119
|
+
return np.array_equal(self.bus_pos, box.bus_pos) and np.array_equal(self.kind, box.kind)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _part_bounds(row: np.void, axis: str) -> tuple[float, float]:
|
|
123
|
+
"""Injection bounds of one node on ``axis`` (``"p"`` / ``"q"``) in MW / Mvar."""
|
|
124
|
+
has_gen, has_load = bool(row["exist_gen"]), bool(row["exist_load"])
|
|
125
|
+
if not (has_gen or has_load):
|
|
126
|
+
return 0.0, 0.0
|
|
127
|
+
lo = hi = 0.0
|
|
128
|
+
if has_gen:
|
|
129
|
+
if axis == "p" and is_reactive_only_generation(
|
|
130
|
+
row["generation_p_min"],
|
|
131
|
+
row["generation_p_max"],
|
|
132
|
+
row["generation_q_min"],
|
|
133
|
+
row["generation_q_max"],
|
|
134
|
+
):
|
|
135
|
+
g_lo, g_hi = 0.0, 0.0 # compensator: no active power, [0, 0] is data
|
|
136
|
+
else:
|
|
137
|
+
g_lo, g_hi = resolve_bounds(
|
|
138
|
+
row[f"generation_{axis}_min"], row[f"generation_{axis}_max"]
|
|
139
|
+
)
|
|
140
|
+
lo += g_lo
|
|
141
|
+
hi += g_hi
|
|
142
|
+
if has_load:
|
|
143
|
+
l_lo, l_hi = resolve_bounds(row[f"load_{axis}_min"], row[f"load_{axis}_max"])
|
|
144
|
+
lo -= l_hi
|
|
145
|
+
hi -= l_lo
|
|
146
|
+
return lo, hi
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def node_injection_boxes(
|
|
150
|
+
nodes_arr: np.ndarray, network_pu: NetworkPU, *, base_mva: float
|
|
151
|
+
) -> NodeBox:
|
|
152
|
+
"""Boxes of the active nodes from the node markup and the generation / load limits.
|
|
153
|
+
|
|
154
|
+
A node with neither ``exist_gen`` nor ``exist_load`` gets the point box
|
|
155
|
+
``[0, 0]`` on both axes. Otherwise the box is the generation range minus the
|
|
156
|
+
load range of the parts the node has; a side left unset by the data
|
|
157
|
+
(:func:`~gridstate.bounds.resolve_bounds`) stays open. A (node, axis) with
|
|
158
|
+
both sides open gets no row.
|
|
159
|
+
"""
|
|
160
|
+
rows = {int(r["id"]): r for r in nodes_arr}
|
|
161
|
+
bus_pos: list[int] = []
|
|
162
|
+
kinds: list[int] = []
|
|
163
|
+
los: list[float] = []
|
|
164
|
+
his: list[float] = []
|
|
165
|
+
for pos, nid in enumerate(network_pu.bus_ids.tolist()):
|
|
166
|
+
row = rows.get(int(nid))
|
|
167
|
+
if row is None or not bool(row["status"]):
|
|
168
|
+
continue
|
|
169
|
+
for axis, kind in (("p", KIND_POWER_INJECTION_P), ("q", KIND_POWER_INJECTION_Q)):
|
|
170
|
+
lo, hi = _part_bounds(row, axis)
|
|
171
|
+
if not (np.isfinite(lo) or np.isfinite(hi)):
|
|
172
|
+
continue
|
|
173
|
+
bus_pos.append(pos)
|
|
174
|
+
kinds.append(kind)
|
|
175
|
+
los.append(lo / base_mva)
|
|
176
|
+
his.append(hi / base_mva)
|
|
177
|
+
return NodeBox(
|
|
178
|
+
bus_pos=np.asarray(bus_pos, dtype=np.int64),
|
|
179
|
+
kind=np.asarray(kinds, dtype=np.int64),
|
|
180
|
+
lo=np.asarray(los, dtype=np.float64),
|
|
181
|
+
hi=np.asarray(his, dtype=np.float64),
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def voltage_boxes(lo: np.ndarray, hi: np.ndarray) -> NodeBox:
|
|
186
|
+
"""V rows of every bus from per-bus bounds in p.u. (``NetworkPU.bus_ids`` order)."""
|
|
187
|
+
n = int(lo.shape[0])
|
|
188
|
+
return NodeBox(
|
|
189
|
+
bus_pos=np.arange(n, dtype=np.int64),
|
|
190
|
+
kind=np.full(n, KIND_VOLTAGE, dtype=np.int64),
|
|
191
|
+
lo=np.asarray(lo, dtype=np.float64),
|
|
192
|
+
hi=np.asarray(hi, dtype=np.float64),
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class BoxActiveSet:
|
|
197
|
+
"""Active set of the bound rows of a :class:`NodeBox` inside one WLS solve.
|
|
198
|
+
|
|
199
|
+
``state`` per row: ``0`` free, ``-1`` pinned at ``lo``, ``+1`` pinned at ``hi``.
|
|
200
|
+
``stage`` is ``0`` before the set starts, then ``1..len(sigma2_schedule)``.
|
|
201
|
+
"""
|
|
202
|
+
|
|
203
|
+
def __init__(
|
|
204
|
+
self,
|
|
205
|
+
box: NodeBox,
|
|
206
|
+
algebra: BaseAlgebra,
|
|
207
|
+
*,
|
|
208
|
+
sigma2_schedule: tuple[float, ...],
|
|
209
|
+
tol: float,
|
|
210
|
+
max_releases: int,
|
|
211
|
+
max_corrections: int = 3,
|
|
212
|
+
) -> None:
|
|
213
|
+
if not sigma2_schedule or any(not (s > 0.0) for s in sigma2_schedule):
|
|
214
|
+
raise ValueError(f"sigma2_schedule must be positive variances, got {sigma2_schedule}")
|
|
215
|
+
self.box = box
|
|
216
|
+
self.algebra = algebra
|
|
217
|
+
self.schedule = tuple(float(s) for s in sigma2_schedule)
|
|
218
|
+
self.tol = float(tol)
|
|
219
|
+
self.max_releases = int(max_releases)
|
|
220
|
+
self.max_corrections = int(max_corrections)
|
|
221
|
+
n = len(box)
|
|
222
|
+
self.state = np.zeros(n, dtype=np.int8)
|
|
223
|
+
self.n_released = np.zeros(n, dtype=np.int64)
|
|
224
|
+
self.n_corrected = np.zeros(n, dtype=np.int64)
|
|
225
|
+
# Target shift of the pinned rows (method of multipliers, last stage).
|
|
226
|
+
self.shift = np.zeros(n, dtype=np.float64)
|
|
227
|
+
self.point = box.lo == box.hi
|
|
228
|
+
self.stage = 0
|
|
229
|
+
self.activated = 0
|
|
230
|
+
self.released = 0
|
|
231
|
+
|
|
232
|
+
@property
|
|
233
|
+
def last_stage(self) -> bool:
|
|
234
|
+
return self.stage == len(self.schedule)
|
|
235
|
+
|
|
236
|
+
def any_active(self) -> bool:
|
|
237
|
+
return bool(self.stage > 0 and np.any(self.state != 0))
|
|
238
|
+
|
|
239
|
+
def n_active(self) -> int:
|
|
240
|
+
return int(np.count_nonzero(self.state))
|
|
241
|
+
|
|
242
|
+
def _bounds(self) -> np.ndarray:
|
|
243
|
+
return np.where(self.state < 0, self.box.lo, self.box.hi)
|
|
244
|
+
|
|
245
|
+
def _targets(self) -> np.ndarray:
|
|
246
|
+
return self._bounds() + self.shift
|
|
247
|
+
|
|
248
|
+
def _weight(self) -> float:
|
|
249
|
+
return 1.0 / self.schedule[self.stage - 1]
|
|
250
|
+
|
|
251
|
+
def injections(self, v: np.ndarray, delta: np.ndarray) -> np.ndarray:
|
|
252
|
+
"""Node injections of the bound rows at ``(v, delta)`` (p.u.)."""
|
|
253
|
+
return np.asarray(self.algebra.evaluate_h(v, delta), dtype=np.float64)
|
|
254
|
+
|
|
255
|
+
def violations(self, h: np.ndarray) -> np.ndarray:
|
|
256
|
+
"""Rows whose injection is outside the box by more than ``tol``."""
|
|
257
|
+
return (h < self.box.lo - self.tol) | (h > self.box.hi + self.tol)
|
|
258
|
+
|
|
259
|
+
def penalty(self, h: np.ndarray) -> float:
|
|
260
|
+
"""Objective part of the active bound rows at injections ``h``."""
|
|
261
|
+
if not self.any_active():
|
|
262
|
+
return 0.0
|
|
263
|
+
act = self.state != 0
|
|
264
|
+
r = self._targets()[act] - h[act]
|
|
265
|
+
return float(self._weight() * (r @ r))
|
|
266
|
+
|
|
267
|
+
def normal_terms(
|
|
268
|
+
self, v: np.ndarray, delta: np.ndarray, h: np.ndarray
|
|
269
|
+
) -> tuple[csr_matrix, np.ndarray]:
|
|
270
|
+
"""``(Hᵀ W H, Hᵀ W r)`` of the active bound rows (dense rhs)."""
|
|
271
|
+
act = (self.state != 0).astype(np.float64)
|
|
272
|
+
w = act * self._weight()
|
|
273
|
+
H = self.algebra.evaluate_jacobian(v, delta)
|
|
274
|
+
Ht_W = scale_csr_rows(H, w).T
|
|
275
|
+
r = np.where(act > 0, self._targets() - h, 0.0)
|
|
276
|
+
return (Ht_W @ H).tocsr(), np.asarray(Ht_W @ r, dtype=np.float64).ravel()
|
|
277
|
+
|
|
278
|
+
def start(self, h: np.ndarray) -> bool:
|
|
279
|
+
"""Enter stage 1 when the converged unconstrained solution leaves a box."""
|
|
280
|
+
if not np.any(self.violations(h)):
|
|
281
|
+
return False
|
|
282
|
+
self.stage = 1
|
|
283
|
+
self.pin(h)
|
|
284
|
+
return True
|
|
285
|
+
|
|
286
|
+
def resume(self, warm: BoxWarmStart, h: np.ndarray) -> bool:
|
|
287
|
+
"""Start in the last stage from the set of a previous solve; ``False`` if it does not fit."""
|
|
288
|
+
if not warm.fits(self.box):
|
|
289
|
+
return False
|
|
290
|
+
self.stage = len(self.schedule)
|
|
291
|
+
self.state[:] = warm.state
|
|
292
|
+
self.shift[:] = warm.shift
|
|
293
|
+
self.pin(h)
|
|
294
|
+
return True
|
|
295
|
+
|
|
296
|
+
def warm_start(self) -> BoxWarmStart | None:
|
|
297
|
+
"""The current set for a warm re-solve; ``None`` before the set started."""
|
|
298
|
+
if self.stage == 0:
|
|
299
|
+
return None
|
|
300
|
+
return BoxWarmStart(
|
|
301
|
+
bus_pos=self.box.bus_pos,
|
|
302
|
+
kind=self.box.kind,
|
|
303
|
+
state=self.state.copy(),
|
|
304
|
+
shift=self.shift.copy(),
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
def pin(self, h: np.ndarray) -> bool:
|
|
308
|
+
"""Pin the free rows whose injection left the box; ``True`` if any."""
|
|
309
|
+
free = self.state == 0
|
|
310
|
+
below = free & (h < self.box.lo - self.tol)
|
|
311
|
+
above = free & (h > self.box.hi + self.tol)
|
|
312
|
+
if not (np.any(below) or np.any(above)):
|
|
313
|
+
return False
|
|
314
|
+
self.state[below] = -1
|
|
315
|
+
self.state[above] = 1
|
|
316
|
+
self.shift[below | above] = 0.0
|
|
317
|
+
self.activated += int(np.count_nonzero(below | above))
|
|
318
|
+
return True
|
|
319
|
+
|
|
320
|
+
def release(self, h: np.ndarray) -> bool:
|
|
321
|
+
"""At a converged point, release the pinned rows the solution pulls inside.
|
|
322
|
+
|
|
323
|
+
The bound row of such a row pushes it outward (its target lies on the
|
|
324
|
+
outer side of the injection): the multiplier has the wrong sign. A row is
|
|
325
|
+
released at most ``max_releases`` times; after that it stays pinned
|
|
326
|
+
(the box holds either way), which stops pin / release cycles. A point
|
|
327
|
+
box is never released.
|
|
328
|
+
"""
|
|
329
|
+
pull = self._targets() - h
|
|
330
|
+
inside = ((self.state < 0) & (pull < 0.0)) | ((self.state > 0) & (pull > 0.0))
|
|
331
|
+
inside &= ~self.point & (self.n_released < self.max_releases)
|
|
332
|
+
if not np.any(inside):
|
|
333
|
+
return False
|
|
334
|
+
self.state[inside] = 0
|
|
335
|
+
self.shift[inside] = 0.0
|
|
336
|
+
self.n_released[inside] += 1
|
|
337
|
+
self.released += int(np.count_nonzero(inside))
|
|
338
|
+
return True
|
|
339
|
+
|
|
340
|
+
def correct(self, h: np.ndarray) -> bool:
|
|
341
|
+
"""Last stage: shift the targets of the pinned rows by what they still miss.
|
|
342
|
+
|
|
343
|
+
A finite bound weight lets the injection stop short of its bound by
|
|
344
|
+
``force · σ²``; moving the target by the miss (the method of
|
|
345
|
+
multipliers) closes it without a heavier weight. A row is shifted at
|
|
346
|
+
most ``max_corrections`` times. ``True`` if any row was shifted.
|
|
347
|
+
"""
|
|
348
|
+
act = (self.state != 0) & (self.n_corrected < self.max_corrections)
|
|
349
|
+
miss = np.where(act, self._bounds() - h, 0.0)
|
|
350
|
+
big = np.abs(miss) > self.tol
|
|
351
|
+
if not np.any(big):
|
|
352
|
+
return False
|
|
353
|
+
# Every pinned row follows its miss (the multipliers converge
|
|
354
|
+
# together); only a row that missed by more than tol uses up a correction.
|
|
355
|
+
self.shift += miss
|
|
356
|
+
self.n_corrected[big] += 1
|
|
357
|
+
return True
|
|
358
|
+
|
|
359
|
+
def advance(self) -> None:
|
|
360
|
+
self.stage += 1
|