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

Improve cancel_computation to enable testing. #4293

Merged

Conversation

geektoni
Copy link
Contributor

@karlnapf @shubham808

This PR contains the first implementation of the new cancel_computation method. It is still a WIP so any comments on it are appreciated. Please see the unit test to see the new behaviour.

EXPECT_TRUE(a.get_check() == 5);
}

TEST(StoppableSGObject, custom_callback_by_user)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test shows more clearly what we are going to do in the future when testing the premature stopping feature.

@@ -40,6 +40,12 @@ rxcpp::subscription CStoppableSGObject::connect_to_signal_handler()
return get_global_signal()->get_observable()->subscribe(subscriber);
}

void CStoppableSGObject::add_callback(std::function<bool()> callback=nullptr)
Copy link
Member

Choose a reason for hiding this comment

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

add suggests to add them to a stack of callbacks

};


Mock_model a;
Copy link
Member

Choose a reason for hiding this comment

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

So how would this be tested with existing machines?

Copy link
Member

Choose a reason for hiding this comment

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

Ok I guess your idea here is that we only test things for the Mock_model once and not again for all the subsequent machines?

}
return true;
}
int m_check;
Copy link
Member

Choose a reason for hiding this comment

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

maybe those two can be renamed to something more descriptive

return false;
};

// We then add the callback
Copy link
Member

Choose a reason for hiding this comment

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

superflous comment :)

// Custom train machine
virtual bool train_machine(CFeatures* data=NULL)
{
for (int k=0; k<10; k++)
Copy link
Member

@karlnapf karlnapf May 22, 2018

Choose a reason for hiding this comment

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

could we rename k to something that indicates it is the "train-loop" counter.
Like "num_iterations_train"

using namespace shogun;
using namespace std;

class Mock_model : public CMachine
Copy link
Member

Choose a reason for hiding this comment

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

MockModel

Copy link
Member

@karlnapf karlnapf left a comment

Choose a reason for hiding this comment

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

Cool!
I guess I am still a bit confused in how we would use this to systematically test (all) existing machines to do something sensible when being stopped. But maybe I am missing something?

@geektoni geektoni force-pushed the feature/callback_cancel_computation branch from 60d08f1 to 2d4c790 Compare May 23, 2018 20:14
Copy link
Member

@vigsterkr vigsterkr left a comment

Choose a reason for hiding this comment

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

minor stuff

if (m_callback)
result_callback = m_callback();

return m_cancel_computation.load() || result_callback;
Copy link
Member

Choose a reason for hiding this comment

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

since it's || maybe it'd be better to have this as:

return (m_callback) ? (m_cancel_computation.load() || result_callback()) : m_cancel_computation.load();

just for the sake of lazy evaluation of or :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems a good idea ;)

TEST(StoppableSGObject, empty_callback)
{
MockModel a;
a.set_callback(nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

you either use the default (nullptr) valued set_callback, i.e. use

a.set_callback();

or remove the default value of the function arg. i would opt for the latter


virtual const char* get_name() const
{
return "Mock_model";
Copy link
Member

Choose a reason for hiding this comment

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

MockModel

@geektoni
Copy link
Contributor Author

@karlnapf regarding the testing of the machine, I was thinking about using the same approach used here #3537 or typed tests of the Google suite. This way we could test their consistency after being stopped.

@vigsterkr vigsterkr merged commit 040692b into shogun-toolbox:develop May 25, 2018
@geektoni geektoni deleted the feature/callback_cancel_computation branch September 16, 2018 19:15
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.

None yet

3 participants