pyconvexity 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ -- ============================================================================
2
+ -- SCENARIO-AWARE ATTRIBUTES AND CONSTRAINTS SCHEMA
3
+ -- Support for multiple scenarios within networks and Python constraint execution
4
+ -- Version 1.0.0
5
+ -- ============================================================================
6
+
7
+ -- ============================================================================
8
+ -- SCENARIOS TABLE
9
+ -- ============================================================================
10
+
11
+ -- Scenarios table - represents different modeling scenarios within a network
12
+ -- The "Main" scenario is the master scenario (explicit, not implicit)
13
+ -- "Master" refers to the fact that this is the main reference scenario
14
+ CREATE TABLE scenarios (
15
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
16
+ network_id INTEGER NOT NULL,
17
+ name TEXT NOT NULL,
18
+ description TEXT,
19
+ is_master BOOLEAN DEFAULT FALSE,
20
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
21
+
22
+ CONSTRAINT fk_scenarios_network
23
+ FOREIGN KEY (network_id) REFERENCES networks(id) ON DELETE CASCADE,
24
+ CONSTRAINT uq_scenarios_network_name
25
+ UNIQUE (network_id, name)
26
+ );
27
+
28
+ -- Index for efficient scenario lookups
29
+ CREATE INDEX idx_scenarios_network ON scenarios(network_id);
30
+ CREATE INDEX idx_scenarios_master ON scenarios(is_master);
31
+
32
+ -- ============================================================================
33
+ -- SCENARIO MANAGEMENT TRIGGERS
34
+ -- ============================================================================
35
+
36
+ -- Ensure exactly one master scenario per network
37
+ CREATE TRIGGER ensure_single_master_scenario
38
+ BEFORE INSERT ON scenarios
39
+ FOR EACH ROW
40
+ WHEN NEW.is_master = TRUE
41
+ BEGIN
42
+ UPDATE scenarios
43
+ SET is_master = FALSE
44
+ WHERE network_id = NEW.network_id AND is_master = TRUE;
45
+ END;
46
+
47
+ -- Ensure exactly one master scenario per network on update
48
+ CREATE TRIGGER ensure_single_master_scenario_update
49
+ BEFORE UPDATE ON scenarios
50
+ FOR EACH ROW
51
+ WHEN NEW.is_master = TRUE AND OLD.is_master = FALSE
52
+ BEGIN
53
+ UPDATE scenarios
54
+ SET is_master = FALSE
55
+ WHERE network_id = NEW.network_id AND is_master = TRUE AND id != NEW.id;
56
+ END;
57
+
58
+ -- Prevent deletion of master scenario
59
+ CREATE TRIGGER prevent_master_scenario_deletion
60
+ BEFORE DELETE ON scenarios
61
+ FOR EACH ROW
62
+ WHEN OLD.is_master = TRUE
63
+ BEGIN
64
+ SELECT RAISE(ABORT, 'Cannot delete master scenario');
65
+ END;
66
+
67
+ -- ============================================================================
68
+ -- SCENARIO UTILITY FUNCTIONS
69
+ -- ============================================================================
70
+
71
+ -- Create a view for easy attribute resolution with scenario inheritance
72
+ CREATE VIEW component_attributes_with_scenario AS
73
+ SELECT
74
+ ca.component_id,
75
+ ca.attribute_name,
76
+ ca.storage_type,
77
+ ca.static_value,
78
+ ca.timeseries_data,
79
+ ca.data_type,
80
+ ca.unit,
81
+ ca.is_input,
82
+ COALESCE(ca.scenario_id, 0) as scenario_id,
83
+ CASE
84
+ WHEN ca.scenario_id IS NULL THEN 'Main'
85
+ ELSE s.name
86
+ END as scenario_name,
87
+ ca.created_at,
88
+ ca.updated_at
89
+ FROM component_attributes ca
90
+ LEFT JOIN scenarios s ON ca.scenario_id = s.id;
91
+
92
+ -- ============================================================================
93
+ -- AUTOMATIC MASTER SCENARIO CREATION
94
+ -- ============================================================================
95
+
96
+ -- Trigger to automatically create "Main" scenario (the master scenario) when a network is created
97
+ -- This ensures every network has exactly one master scenario that serves as the main reference
98
+ CREATE TRIGGER create_master_scenario_for_network
99
+ AFTER INSERT ON networks
100
+ FOR EACH ROW
101
+ BEGIN
102
+ INSERT INTO scenarios (network_id, name, description, is_master)
103
+ VALUES (NEW.id, 'Main', 'Main scenario (default)', TRUE);
104
+ END;
105
+
106
+ -- ============================================================================
107
+ -- COMPONENT VALIDATION FOR CONSTRAINT
108
+ -- ============================================================================
109
+
110
+ -- Note: CONSTRAINT components can have NULL carrier_id - this is now enforced
111
+ -- by the CHECK constraint in the components table schema
112
+
113
+ -- ============================================================================
114
+ -- INITIALIZATION
115
+ -- ============================================================================
116
+
117
+ -- This schema extends the existing core schema with scenario support
118
+ -- "Main" scenarios (master scenarios) are automatically created for existing networks
119
+ INSERT INTO scenarios (network_id, name, description, is_master)
120
+ SELECT id, 'Main', 'Main scenario (default)', TRUE
121
+ FROM networks
122
+ WHERE id NOT IN (SELECT network_id FROM scenarios WHERE is_master = TRUE);
@@ -334,7 +334,9 @@ def serialize_timeseries_to_parquet(timeseries: List[TimeseriesPoint]) -> bytes:
334
334
 
335
335
  if not timeseries:
336
336
  # Return empty parquet file with correct schema
337
- table = pa.table([], schema=schema)
337
+ empty_period_array = pa.array([], type=pa.int32())
338
+ empty_value_array = pa.array([], type=pa.float64())
339
+ table = pa.table([empty_period_array, empty_value_array], schema=schema)
338
340
  else:
339
341
  # Create PyArrow table with EXPLICIT schema to ensure data types match Rust
340
342
  period_indices = [p.period_index for p in timeseries]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyconvexity
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Python library for energy system modeling and optimization with PyPSA
5
5
  Author-email: Convexity Team <info@convexity.com>
6
6
  License: MIT
@@ -0,0 +1,20 @@
1
+ pyconvexity/__init__.py,sha256=mEtafBwQ1A9s-hEv3o3XeXlJ7iFtbdS691wVUUw5miY,3303
2
+ pyconvexity/_version.py,sha256=Cu2pGbVzHvik6YUUC3R9lxs9dHnXZq1Uj0YfLLblLUs,133
3
+ pyconvexity/core/__init__.py,sha256=4SYAE4zqzGIRFSP4IoT7EzK-LCTB1HLe9EWhfi2aUmU,1253
4
+ pyconvexity/core/database.py,sha256=4OW1sgwDT4ltxdW6b250ytTlsC9sk26Rz0VrveXSL4A,9605
5
+ pyconvexity/core/errors.py,sha256=HhrrOOEBJrzyB56_pmqh3NWvX6uHqWWNkdE5XM16rYI,2881
6
+ pyconvexity/core/types.py,sha256=eoVOAcDJWzjJKO9lYN7O17Us0XbahBpVBwv6uxdldh0,8508
7
+ pyconvexity/data/schema/01_core_schema.sql,sha256=Vt6vASZEASPPQYuhtsARLj3PxP7VdZtfxmGcs-Id-xc,18785
8
+ pyconvexity/data/schema/02_data_metadata.sql,sha256=9E7tnBBu0wc4w3YijyPf_vG_8KVFyu7cu59TyAP5F94,21818
9
+ pyconvexity/data/schema/03_validation_data.sql,sha256=1rKFi9y6jQ2OnfH32jnIKnZ5WtB8eG43hz0OVJhwn3w,58325
10
+ pyconvexity/data/schema/04_scenario_schema.sql,sha256=sL4PySJNHIthXsnoJ2T5pdXUbpAi94ld0XGuU8LwNuQ,4641
11
+ pyconvexity/models/__init__.py,sha256=eVwf0ZTTEq1nM9M3NSMvj2yLPUOPNKMXv2A5GLT34-c,1470
12
+ pyconvexity/models/attributes.py,sha256=gh02j_hpSeyCNg0Jt20i7Y7wOntajnuzI926W5wzA3Q,14130
13
+ pyconvexity/models/components.py,sha256=K7QWelMVU_D18skvBZbap9dxP2AMS2116fcpmemkE6U,14629
14
+ pyconvexity/models/network.py,sha256=-itmot8StUdXogDpZUhGVIUC5uAEucYQ1LiTN1vPdA4,12923
15
+ pyconvexity/validation/__init__.py,sha256=_6SVqXkaDFqmagub_O064Zm_QIdBrOra-Gvvbo9vM4I,549
16
+ pyconvexity/validation/rules.py,sha256=bshO2Ibw8tBurg708Dmf79rIBoGV32t-jNHltjap9Pw,9323
17
+ pyconvexity-0.1.2.dist-info/METADATA,sha256=Lmk43_bNLN4jVbnqynhutZq9sK29vywiwbKBFjAWL7M,4751
18
+ pyconvexity-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ pyconvexity-0.1.2.dist-info/top_level.txt,sha256=wFPEDXVaebR3JO5Tt3HNse-ws5aROCcxEco15d6j64s,12
20
+ pyconvexity-0.1.2.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- pyconvexity/__init__.py,sha256=mEtafBwQ1A9s-hEv3o3XeXlJ7iFtbdS691wVUUw5miY,3303
2
- pyconvexity/_version.py,sha256=5CA6z91JO_fS9ADhN6383Ps_rUNBx3K4gJNbVRJmeYY,133
3
- pyconvexity/core/__init__.py,sha256=4SYAE4zqzGIRFSP4IoT7EzK-LCTB1HLe9EWhfi2aUmU,1253
4
- pyconvexity/core/database.py,sha256=zqurVzPGuWei0jII1PTMAY-qaR-fr_A7uLxm__6KIlE,9276
5
- pyconvexity/core/errors.py,sha256=HhrrOOEBJrzyB56_pmqh3NWvX6uHqWWNkdE5XM16rYI,2881
6
- pyconvexity/core/types.py,sha256=eoVOAcDJWzjJKO9lYN7O17Us0XbahBpVBwv6uxdldh0,8508
7
- pyconvexity/models/__init__.py,sha256=eVwf0ZTTEq1nM9M3NSMvj2yLPUOPNKMXv2A5GLT34-c,1470
8
- pyconvexity/models/attributes.py,sha256=I6t1x7HX1gLw_lA6K87_GGmLAO34fpe4ZDX7_3LzMx4,13974
9
- pyconvexity/models/components.py,sha256=K7QWelMVU_D18skvBZbap9dxP2AMS2116fcpmemkE6U,14629
10
- pyconvexity/models/network.py,sha256=-itmot8StUdXogDpZUhGVIUC5uAEucYQ1LiTN1vPdA4,12923
11
- pyconvexity/validation/__init__.py,sha256=_6SVqXkaDFqmagub_O064Zm_QIdBrOra-Gvvbo9vM4I,549
12
- pyconvexity/validation/rules.py,sha256=bshO2Ibw8tBurg708Dmf79rIBoGV32t-jNHltjap9Pw,9323
13
- pyconvexity-0.1.0.dist-info/METADATA,sha256=ltUWa115nNRTIAl4xbzFDjC2s9Q5LOhJcJHwMBS6ea4,4751
14
- pyconvexity-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- pyconvexity-0.1.0.dist-info/top_level.txt,sha256=wFPEDXVaebR3JO5Tt3HNse-ws5aROCcxEco15d6j64s,12
16
- pyconvexity-0.1.0.dist-info/RECORD,,