pyconvexity 0.4.8__py3-none-any.whl → 0.4.9__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.

Potentially problematic release.


This version of pyconvexity might be problematic. Click here for more details.

pyconvexity/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.4.8"
1
+ __version__ = "0.4.9"
@@ -149,9 +149,17 @@ class NetworkSolver:
149
149
  run_id = str(uuid.uuid4())
150
150
 
151
151
  try:
152
- # Get solver configuration
152
+ # Extract PyPSA-specific options that shouldn't be passed to the solver
153
+ pypsa_options = {}
154
+ filtered_solver_options = solver_options.copy() if solver_options else {}
155
+
156
+ # linearized_unit_commitment is a PyPSA option, not a solver option
157
+ if filtered_solver_options.get('linearized_unit_commitment'):
158
+ pypsa_options['linearized_unit_commitment'] = filtered_solver_options.pop('linearized_unit_commitment')
159
+
160
+ # Get solver configuration (with filtered options)
153
161
  actual_solver_name, solver_config = self._get_solver_config(
154
- solver_name, solver_options, custom_solver_config
162
+ solver_name, filtered_solver_options if filtered_solver_options else None, custom_solver_config
155
163
  )
156
164
 
157
165
  # Resolve discount rate - fallback to 0.0 if None
@@ -197,19 +205,22 @@ class NetworkSolver:
197
205
  # NOTE: Model constraints are applied DURING solve via extra_functionality
198
206
  # Network constraints were already applied to the network structure before solve
199
207
 
208
+ # Build optimize kwargs
209
+ optimize_kwargs = {
210
+ 'solver_name': actual_solver_name,
211
+ 'multi_investment_periods': True,
212
+ 'extra_functionality': extra_functionality,
213
+ }
214
+
215
+ # Add solver config if present
200
216
  if solver_config:
201
- result = network.optimize(
202
- solver_name=actual_solver_name,
203
- multi_investment_periods=True,
204
- extra_functionality=extra_functionality,
205
- **solver_config,
206
- )
207
- else:
208
- result = network.optimize(
209
- solver_name=actual_solver_name,
210
- multi_investment_periods=True,
211
- extra_functionality=extra_functionality,
212
- )
217
+ optimize_kwargs.update(solver_config)
218
+
219
+ # Add PyPSA-specific options (like linearized_unit_commitment)
220
+ if pypsa_options:
221
+ optimize_kwargs.update(pypsa_options)
222
+
223
+ result = network.optimize(**optimize_kwargs)
213
224
 
214
225
  solve_time = time.time() - start_time
215
226
 
@@ -385,7 +396,7 @@ class NetworkSolver:
385
396
  mosek_default_options = {
386
397
  "solver_options": {
387
398
  "MSK_DPAR_MIO_REL_GAP_CONST": 0.05, # MIP relative gap tolerance (5% to match Gurobi)
388
- "MSK_IPAR_MIO_MAX_TIME": 36000, # Max time 1 hour
399
+ "MSK_DPAR_MIO_MAX_TIME": 36000, # Max time 10 hours
389
400
  }
390
401
  }
391
402
  if solver_options:
@@ -448,7 +459,7 @@ class NetworkSolver:
448
459
  mosek_defaults = {
449
460
  "solver_options": {
450
461
  "MSK_DPAR_MIO_REL_GAP_CONST": 0.05, # Match Gurobi 5% MIP gap (was 1e-4)
451
- "MSK_IPAR_MIO_MAX_TIME": 36000, # Max time 1 hour
462
+ "MSK_DPAR_MIO_MAX_TIME": 36000, # Max time 10 hours
452
463
  "MSK_IPAR_NUM_THREADS": 0, # Use all cores (0 = auto)
453
464
  }
454
465
  }
@@ -4,12 +4,16 @@ Result storage functionality for PyPSA solver integration.
4
4
  Handles storing solve results back to the database with proper validation and error handling.
5
5
  """
6
6
 
7
+ import logging
7
8
  import uuid
8
9
  import pandas as pd
9
10
  import numpy as np
10
11
  from typing import Dict, Any, Optional, Callable
11
12
 
12
13
  from pyconvexity.core.types import StaticValue
14
+
15
+ logger = logging.getLogger(__name__)
16
+
13
17
  from pyconvexity.models import (
14
18
  list_components_by_type,
15
19
  set_static_attribute,
@@ -220,7 +224,6 @@ class ResultStorage:
220
224
  Returns:
221
225
  Number of buses with clearing prices stored
222
226
  """
223
- logger.info(f"=== CALCULATING AND STORING CLEARING PRICES (scenario_id={scenario_id}) ===")
224
227
 
225
228
  try:
226
229
  from .clearing_price import ClearingPriceCalculator
@@ -233,21 +236,14 @@ class ResultStorage:
233
236
  return 0
234
237
 
235
238
  # Log what we got from the calculator
236
- logger.info(f"Clearing prices calculated for {len(clearing_prices)} buses")
237
239
  for bus_name, prices in clearing_prices.items():
238
240
  n_zeros = np.sum(prices == 0)
239
241
  n_inf = np.sum(np.isinf(prices))
240
242
  valid = prices[(prices > 0) & np.isfinite(prices)]
241
- if len(valid) > 0:
242
- logger.info(f" {bus_name}: {len(prices)} periods, mean=£{np.mean(valid):.2f}, "
243
- f"zeros={n_zeros}, inf={n_inf}, range=[£{np.min(valid):.2f}, £{np.max(valid):.2f}]")
244
- else:
245
- logger.warning(f" {bus_name}: {len(prices)} periods, ALL ZERO OR INF (zeros={n_zeros}, inf={n_inf})")
246
-
243
+
247
244
  # Get bus component IDs
248
245
  buses = list_components_by_type(conn, "BUS")
249
246
  bus_name_to_id = {bus.name: bus.id for bus in buses}
250
- logger.info(f"Found {len(buses)} buses in database: {list(bus_name_to_id.keys())}")
251
247
 
252
248
  stored_count = 0
253
249
  for bus_name, prices in clearing_prices.items():
@@ -268,14 +264,12 @@ class ResultStorage:
268
264
  conn, bus_id, "clearing_price", values, scenario_id
269
265
  )
270
266
  stored_count += 1
271
- logger.info(f" ✅ {bus_name} (id={bus_id}): stored {len(values)} clearing prices")
272
267
  except Exception as e:
273
268
  logger.error(f" ❌ {bus_name} (id={bus_id}): failed to store clearing_price: {e}")
274
269
  import traceback
275
270
  traceback.print_exc()
276
271
  continue
277
272
 
278
- logger.info(f"=== CLEARING PRICES: Stored {stored_count}/{len(clearing_prices)} buses ===")
279
273
  return stored_count
280
274
 
281
275
  except ImportError as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyconvexity
3
- Version: 0.4.8
3
+ Version: 0.4.9
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
@@ -1,5 +1,5 @@
1
1
  pyconvexity/__init__.py,sha256=P67QJ8npf-QWmBX12im__eICLoRz8cByQ5OJXiyIBmA,5706
2
- pyconvexity/_version.py,sha256=40-PUZPRIakJU2yYWQcwTYvSJA6iewqiG8XylhxuAQk,22
2
+ pyconvexity/_version.py,sha256=LdxLMJM_JXsCQBeSvnxCNyGWmINE0yWfna3DQaT41Vs,22
3
3
  pyconvexity/dashboard.py,sha256=7x04Hr-EwzTAf-YJdHzfV83Gf2etltwtzwh_bCYJ5lk,8579
4
4
  pyconvexity/timeseries.py,sha256=QdKbiqjAlxkJATyKm2Kelx1Ea2PsAnnCYfVLU5VER1Y,11085
5
5
  pyconvexity/core/__init__.py,sha256=gdyyHNqOc4h9Nfe9u6NA936GNzH6coGNCMgBvvvOnGE,1196
@@ -34,11 +34,11 @@ pyconvexity/solvers/pypsa/batch_loader.py,sha256=ZgOcZqMnMS3TOYTq2Ly2O4cuwhNNAic
34
34
  pyconvexity/solvers/pypsa/builder.py,sha256=1ZU68Wtl_jQSXHzspKQDkR6bxAVU1nKvPfnPUl0aO3k,23256
35
35
  pyconvexity/solvers/pypsa/clearing_price.py,sha256=HdAk7GPfJFVI4t6mL0zQGEOMAvuyfpl0yNCnah1ZGH0,29164
36
36
  pyconvexity/solvers/pypsa/constraints.py,sha256=20WliFDhPQGMAsS4VOTU8LZJpsFpLVRHpNsZW49GTcc,16397
37
- pyconvexity/solvers/pypsa/solver.py,sha256=M-s-VUCnRD8Jdh22PCUA-gWgYp1eH6_sgpoSzcv6kNQ,59762
38
- pyconvexity/solvers/pypsa/storage.py,sha256=-plXsEWDAxdDESryNTLxE7gmKqhH0lvoiQTFPVBlUY4,96046
37
+ pyconvexity/solvers/pypsa/solver.py,sha256=iVgDsmYK7AvutkpuNoW_DoLAKODFJTFA2W1cCo1yhPQ,60427
38
+ pyconvexity/solvers/pypsa/storage.py,sha256=KcHIK3wgYjs7oV4tAqWU3HnxJcC_5MoylLoPuAECmDU,95195
39
39
  pyconvexity/validation/__init__.py,sha256=VJNZlFoWABsWwUKktNk2jbtXIepH5omvC0WtsTS7o3o,583
40
40
  pyconvexity/validation/rules.py,sha256=GiNadc8hvbWBr09vUkGiLLTmSdvtNSeGLFwvCjlikYY,9241
41
- pyconvexity-0.4.8.dist-info/METADATA,sha256=1XoACQku7fC6MNJ0oeGm59kRAabONcs5oyrFE5WCOnU,4967
42
- pyconvexity-0.4.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
43
- pyconvexity-0.4.8.dist-info/top_level.txt,sha256=wFPEDXVaebR3JO5Tt3HNse-ws5aROCcxEco15d6j64s,12
44
- pyconvexity-0.4.8.dist-info/RECORD,,
41
+ pyconvexity-0.4.9.dist-info/METADATA,sha256=Po_2qtmjGEUegJTuGGVOwagD4uH97bFNjM6o4O6bmdU,4967
42
+ pyconvexity-0.4.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
43
+ pyconvexity-0.4.9.dist-info/top_level.txt,sha256=wFPEDXVaebR3JO5Tt3HNse-ws5aROCcxEco15d6j64s,12
44
+ pyconvexity-0.4.9.dist-info/RECORD,,