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

Factor out auto path optimizer + allow shapes in contract_path #84

Merged
merged 4 commits into from
Feb 20, 2019

Conversation

jcmgray
Copy link
Collaborator

@jcmgray jcmgray commented Feb 20, 2019

Description

A couple of minor-ish path tweaks:

  1. Factor out the 'auto' path logic to an actual path function (closes FR: separate 'auto' strategy out of contract_path #82) cc @fritzo
  2. Allow contract_path to accept shapes with the option shapes=True (rather than requiring actual array-like objects as now)

The path options and auto path choosing based on size I've implemented as dictionaries, which as well as for efficiencies sake potentially allows them to be customized in the future. E.g. users adding their own named optimizers options or setting custom 'auto' strategies.

Status

  • Ready to go

@jcmgray jcmgray changed the title Factor out auto path optimizer Factor out auto path optimizer + allow shapes in contract_path Feb 20, 2019
@codecov-io
Copy link

codecov-io commented Feb 20, 2019

Codecov Report

Merging #84 into master will increase coverage by 0.42%.
The diff coverage is 100%.

def add_path_fn(name, fn):
"""Add path finding function ``fn`` as an option with ``name``.
"""
_PATH_OPTIONS[name] = fn
Copy link
Owner

Choose a reason for hiding this comment

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

Can we 1) lowercase name and 2) make sure the key does not already exist?

@@ -372,3 +372,6 @@ def random_greedy(inputs, output, idx_dict, memory_limit=None, **optimizer_kwarg
"""
optimizer = RandomGreedy(**optimizer_kwargs)
return optimizer(inputs, output, idx_dict, memory_limit)


paths.add_path_fn('random-greedy', random_greedy)
Copy link
Owner

Choose a reason for hiding this comment

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

I do like the registration, but the potential circular imports worry me a bit. What do you think of imports the path finders into paths.py and register them there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the registration was my way of getting round the circular import problem since path_random depends on paths quite a bit. However switching to from . import paths in this file might have sorted that already. Alternatively, could perform the registration in the top __init__?

Copy link
Owner

Choose a reason for hiding this comment

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

The from . imports paths did prevent the circular depends in this particular case, but is quite vulnerable to problems in the future. Perhaps we could split off registration into another file or as you said, add it to the init.

}


def add_path_fn(name, fn):
Copy link
Owner

Choose a reason for hiding this comment

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

Could we call this register_path_fn, would make the language slightly clearer I believe.

@jcmgray
Copy link
Collaborator Author

jcmgray commented Feb 20, 2019

I've made those changes @dgasmith and moved the random-greedy registration into the top __init__.

}


def register_path_fn(name, fn, overwrite=False):
Copy link
Owner

Choose a reason for hiding this comment

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

I would vote against an overwrite option here. This could give the ability for folks to override the definitions of paths in our code. Choosing another name is equally easy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure thing, I was thinking here one might want to update a function, but this can still be explicitly done by deleting the key first.

Copy link
Owner

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@dgasmith dgasmith merged commit f9afb0b into dgasmith:master Feb 20, 2019
@dgasmith dgasmith added this to the v3.0 milestone Jul 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: separate 'auto' strategy out of contract_path
3 participants