diff --git a/cml/domain/deconstruction.py b/cml/domain/deconstruction.py index b4f3b7453a27517e194e7dad434d5b63a8c5314f..02d23c89635832cdc84eeb36e80544b098abf680 100644 --- a/cml/domain/deconstruction.py +++ b/cml/domain/deconstruction.py @@ -272,13 +272,12 @@ class Deconstructor: self.source = source self.logger = None self.reconstructor = None - self.free_id = None def _strategies(self, block): - yield (("T", "Sigma"), partial(self.deconstruct_time_sigma, block=block)) - yield (("T", "Z"), partial(self.deconstruct_time_zeta, block=block)) - yield (("Sigma", "Z"), partial(self.deconstruct_sigma_zeta, block=block)) yield (("complete", ), partial(self.deconstruct_complete, block=block)) + yield (("Sigma", "Z"), partial(self.deconstruct_sigma_zeta, block=block)) + yield (("T", "Sigma"), partial(self.deconstruct_time_sigma, block=block)) + # yield (("T", "Z"), partial(self.deconstruct_time_zeta, block=block)) @log def deconstruct(self, @@ -286,6 +285,7 @@ class Deconstructor: prag_model: PragmaticMachineLearningModel, learnblock) -> None: + success = False ################################################################### self.logger.protocol(self.settings) self.logger.protocol("{:<20}: {}".format("Pragmatic", str(prag_model))) @@ -305,31 +305,29 @@ class Deconstructor: try: strategy(tier, prag_model, relative) - ########################################################### - self.logger.protocol("Deconstruction SUCCESS!") - ########################################################### + success = True if self.settings.deconst_mode == "minimal": return except NoModelReconstructedError: continue except DeconstructionFailed: - ########################################################### - self.logger.protocol("Deconstruction FAILED!") - ########################################################### continue except Exception as error: print(error.with_traceback()) + if not success: + # All deconstructions failed, so save the pragmatic model + self.knowledge_database.insert(prag_model) + def deconstruct_time_sigma(self, tier: int, p_model: PragmaticMachineLearningModel, r_model: PragmaticMachineLearningModel, block): success = False - self.knowledge_database.insert(p_model) - if r_model and p_model.tier < HIGHEST_TIER-1: + if r_model and p_model.tier < self.settings.highest_tier-1: # Get learnblock that trained relative model second_block = r_model.trained_with(self.source) @@ -459,7 +457,6 @@ class Deconstructor: self.knowledge_database.insert(r_model) if not success: - self.knowledge_database.insert(p_model) raise DeconstructionFailed() def time_constraint(self,