Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue1081 #245

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Issue1081 #245

wants to merge 19 commits into from

Conversation

SimonDold
Copy link
Contributor

@SimonDold SimonDold changed the title issue 1081 Issue1081 Feb 3, 2025
#ifndef UTILS_COMPONENT_ERRORS_H
#define UTILS_COMPONENT_ERRORS_H

#include "exceptions.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this include needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it is used in line 9 for the base class.

@@ -4,6 +4,7 @@
#include "../evaluation_result.h"

#include "../plugins/plugin.h"
#include "../utils/component_errors.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include is present in some files that use verification functions and missing from others. I suggest removing it from all files that include plugin.h, because plugin.h includes component_errors.h anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this change is to make the errors that can happen during class creation independent of the plugin code. Once we can create features through a Python interface, the plugin code is no longer involved in the object creation, but validation code like the parts in this diff should still run. Because of that, I would see the include through plugin.h as coincidental and not the intended way of including the error.

#include <vector>

namespace utils {
class ComponentArgumentError : public Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name ComponentArgumentError sounds like this is inherently tied to plugins. But the functionality can now be used by any class or function. So I think it makes sense to give it a more generic name. ValueError comes to mind since it's the equivalent from Python.

If you only want "plugin classes" to use the functions below, the ComponentArgumentError should live in plugin.h, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should only be used by "components" and we want to treat our plugin code as optional for components. For example, the Python interface could create components without using plugins. "Plugins" are a feature related to the command line parsing, e.g., where you transform a string like astar(lmcut()) into components. In one of the draft PRs dealing with the component interaction problem, we introduce a base class for all components. Once we have that class, I think it would make sense for ComponentArgumentError to live next to it.

@@ -4,6 +4,7 @@
#include "../evaluation_result.h"

#include "../plugins/plugin.h"
#include "../utils/component_errors.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this change is to make the errors that can happen during class creation independent of the plugin code. Once we can create features through a Python interface, the plugin code is no longer involved in the object creation, but validation code like the parts in this diff should still run. Because of that, I would see the include through plugin.h as coincidental and not the intended way of including the error.

@@ -34,6 +35,10 @@ LabelReduction::LabelReduction(
lr_method(method),
lr_system_order(system_order),
rng(utils::get_rng(random_seed)) {
utils::verify_comparison(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function feels a bit over-engineered. Wouldn't something like this work:

utils::verify_argument(lr_before_shrinking || lr_before_merging, "...");

If you keep it, I would suggest to change the argument order, though, so it reads as "arg1, OR, arg2", rather than "arg1, arg2, OR".

assert(max_states_before_merge > 0);
assert(max_states >= max_states_before_merge);
// TODO why is this assert comparing threshold to max_states_before_merge
// while the default handling checks the comparison of threshold to max_states
assert(shrink_threshold_before_merge <= max_states_before_merge);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this could be violated.

}
}

// TODO are these asserts needed?
assert(max_states_before_merge > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is strange to write it as > 0 here and >= 1 in the test above. For the same reason, I would also write teh assumptions in lines 114, 115, and 118 in the same direction, rather than using a < b once and c > b another time.

Also, the assert just after the test seems redundant. Maybe the asserts should be in the constructor to show readers at one glance what properties we guarantee after construction.

/* A soft limit for triggering shrinking even if the hard limits
max_states and max_states_before_merge are not violated. */
const int shrink_threshold_before_merge;
int shrink_threshold_before_merge;

// Options for pruning
const bool prune_unreachable_states;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are removing the const, I'd remove this one as well.

std::shared_ptr<Base> ptr = this->create_component(options, context);
std::shared_ptr<Base> ptr;
try {
ptr = this->create_component(options, context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Why) do we need this here?

#ifndef UTILS_COMPONENT_ERRORS_H
#define UTILS_COMPONENT_ERRORS_H

#include "exceptions.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it is used in line 9 for the base class.

#include <vector>

namespace utils {
class ComponentArgumentError : public Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should only be used by "components" and we want to treat our plugin code as optional for components. For example, the Python interface could create components without using plugins. "Plugins" are a feature related to the command line parsing, e.g., where you transform a string like astar(lmcut()) into components. In one of the draft PRs dealing with the component interaction problem, we introduce a base class for all components. Once we have that class, I think it would make sense for ComponentArgumentError to live next to it.

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.

4 participants