Skip to content

Commit fa77d03

Browse files
committed
Refactor cyipopt import to be lazy-loaded in RobotIPOPTSolver
1 parent 2ae3dd5 commit fa77d03

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/figaroh/tools/robotipopt.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,6 @@ def constraints(self, x):
166166
from dataclasses import dataclass, field
167167
from typing import Dict, List, Tuple, Optional, Any, Callable, Union
168168

169-
try:
170-
import cyipopt
171-
except ImportError:
172-
raise ImportError(
173-
"cyipopt is required for IPOPT optimization. "
174-
"Install with: pip install cyipopt"
175-
)
176-
177169

178170
@dataclass
179171
class IPOPTConfig:
@@ -752,6 +744,15 @@ def solve(self) -> Tuple[bool, Dict[str, Any]]:
752744
indicate various types of failures or early termination.
753745
"""
754746
try:
747+
# Import cyipopt only when needed
748+
try:
749+
import cyipopt
750+
except ImportError:
751+
raise ImportError(
752+
"cyipopt is required for IPOPT optimization. "
753+
"Install with: pip install cyipopt"
754+
)
755+
755756
self.logger.info(f"Setting up IPOPT problem: {self.problem.name}")
756757

757758
# Get problem dimensions and bounds

0 commit comments

Comments
 (0)