Skip to content

Fix a bug where duplicated objectives can be passed#96

Open
tautomer wants to merge 1 commit intoMSDLLCpapers:mainfrom
tautomer:fix_dup
Open

Fix a bug where duplicated objectives can be passed#96
tautomer wants to merge 1 commit intoMSDLLCpapers:mainfrom
tautomer:fix_dup

Conversation

@tautomer
Copy link
Collaborator

@tautomer tautomer commented Mar 18, 2026

Proposed fix for #95

    def suggest(self, **optim_kwargs):
        """
        Maps Optimizer.suggest method
        """
        if self.optimizer.is_fit:
            try:
                # In case X_space has changed, re-set the optimizer X_space
                self.optimizer.set_X_space(self.X_space)
                if "objective" not in optim_kwargs:
                    optim_kwargs["objective"] = self.objective
                X, eval = self.optimizer.suggest(
                    out_constraints=self.output_constraints,
                    **optim_kwargs,
                )
                return (X, eval)
            except Exception as e:
                warnings.warn('Optimization failed')
                print("Error message:", e)
                # print full traceback for debugging verbosity
                if self.optimizer.verbose > 2:
                    print("Stack trace:", traceback.format_exc())
                return None

class objective always takes priority and passed-in objective= is silently suppressed (might be bad for UX perspective. optionally raise a warning?)

Full traceback is printed out when verbosity > 2 (2 might be too high for critical messages like this).

@tautomer tautomer linked an issue Mar 18, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible duplicated objective allowed in campaign

1 participant