@@ -1104,6 +1104,15 @@ def _solve_feature(self, feature, rebuild=True):
11041104 self ._use_fallback (name , builders , unconverged , fallback , "did not converge" )
11051105 feature .builder .up_to_date ()
11061106
1107+ def _forget_native_state (self , name = None ):
1108+ """Let the feature `name` (or every feature) try the native solver again."""
1109+ if name is None :
1110+ self ._native_failed .clear ()
1111+ self ._native_fallbacks .clear ()
1112+ return
1113+ self ._native_failed .discard (name )
1114+ self ._native_fallbacks .pop (name , None )
1115+
11071116 @staticmethod
11081117 def _set_fallback (builder , fallback ):
11091118 # the native iteration limit is not for the other solvers
@@ -1155,9 +1164,10 @@ def _model_area(self) -> float:
11551164 """Return the map (XY) area of the model box, or 0 if the box is not set."""
11561165 bounding_box = getattr (self .model , 'bounding_box' , None )
11571166 try :
1158- lengths = np .asarray (bounding_box .maximum , dtype = float )[:2 ] - np .asarray (
1159- bounding_box .origin , dtype = float
1160- )[:2 ]
1167+ lengths = (
1168+ np .asarray (bounding_box .maximum , dtype = float )[:2 ]
1169+ - np .asarray (bounding_box .origin , dtype = float )[:2 ]
1170+ )
11611171 except (AttributeError , TypeError , ValueError , IndexError ):
11621172 return 0.0
11631173 area = float (np .prod (lengths ))
@@ -1422,9 +1432,7 @@ def _group_by_name(self, name):
14221432 def detached_to_dict (self ) -> dict :
14231433 """Return `detached` in a form that `json.dump` can write."""
14241434 return {
1425- name : {
1426- 'columns' : {str (c ): [_json_value (v ) for v in data [c ]] for c in data .columns }
1427- }
1435+ name : {'columns' : {str (c ): [_json_value (v ) for v in data [c ]] for c in data .columns }}
14281436 for name , data in self .detached .items ()
14291437 }
14301438
@@ -1659,7 +1667,13 @@ def mark_data_dirty(self):
16591667 def remove_parametric_fault (self , name : str ):
16601668 """Stop building the parametric fault `name`. The model is stale until the next build."""
16611669 if self .parametric_faults .pop (name , None ) is not None :
1670+ self .nelements_overrides .pop (name , None )
1671+ self .nelements_used .pop (name , None )
1672+ self ._data_summaries .pop (name , None )
1673+ self ._needs_inequalities .discard (name )
1674+ self ._forget_native_state (name )
16621675 self ._data_dirty = True
1676+ self ._emit ('model_updated' )
16631677
16641678 def _build_parametric_faults (self ):
16651679 for name , spec in self .parametric_faults .items ():
@@ -1677,13 +1691,22 @@ def _build_parametric_faults(self):
16771691
16781692 def parametric_faults_to_dict (self ) -> dict :
16791693 """Return `parametric_faults` in a form that `json.dump` can write."""
1680- return {name : parametric_fault .clean_spec (spec ) for name , spec in self .parametric_faults .items ()}
1694+ return {
1695+ name : parametric_fault .clean_spec (spec ) for name , spec in self .parametric_faults .items ()
1696+ }
16811697
16821698 def parametric_faults_from_dict (self , faults : dict ):
16831699 """Replace `parametric_faults` with the specs from `parametric_faults_to_dict`."""
1684- self .parametric_faults = {
1685- name : parametric_fault .spec_from_dict (spec ) for name , spec in (faults or {}).items ()
1686- }
1700+ self .parametric_faults = {}
1701+ for name , spec in (faults or {}).items ():
1702+ # one damaged fault must not stop the restore of the project
1703+ try :
1704+ self .parametric_faults [name ] = parametric_fault .spec_from_dict (spec )
1705+ except ValueError as error :
1706+ if self ._debug_manager is not None :
1707+ self ._debug_manager .log (
1708+ f"Skipped the saved parametric fault '{ name } ': { error } " , log_level = 2
1709+ )
16871710
16881711 def _get_feature_by_name_or_none (self , name ):
16891712 """Non-raising counterpart to `GeologicalModel.get_feature_by_name`.
@@ -1883,6 +1906,8 @@ def update_model(
18831906 self .model .features = []
18841907 self .model .feature_name_index = {}
18851908 self .skipped_constraints = {}
1909+ # The data is read again, so a feature can use the native solver again
1910+ self ._forget_native_state ()
18861911
18871912 # Notify start (if requested) so UI can react
18881913 if notify_observers :
@@ -1980,6 +2005,8 @@ def refresh_feature_data(self) -> dict:
19802005 """
19812006 updated = []
19822007 needs_initialize = []
2008+ # The data paths below add the features that need inequalities again
2009+ self ._needs_inequalities .clear ()
19832010
19842011 def refresh (name , data ):
19852012 feature = self ._get_feature_by_name_or_none (name )
@@ -2000,6 +2027,8 @@ def refresh(name, data):
20002027 if isinstance (current , pd .DataFrame ) and current .equals (data ):
20012028 return
20022029 target .add_data_from_data_frame (data )
2030+ # new data can be solved by the native solver
2031+ self ._forget_native_state (name )
20032032 # add_data_from_data_frame does not reset this flag, and while
20042033 # it is set the builder keeps the constraints of the old data
20052034 target .data_added = False
0 commit comments