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

Allow any type of state variable #19

Closed
matsulib opened this issue Aug 17, 2017 · 1 comment
Closed

Allow any type of state variable #19

matsulib opened this issue Aug 17, 2017 · 1 comment

Comments

@matsulib
Copy link
Contributor

I could use type numpy.ndarray or pandas.DataFrame for state variable from #12.
Unfortunately, the patch of #12 was canceled by ed97524.
There seems to be a little confusion.

I have a suggestion about this code.

class Annealer(object):
    def __init__(self, initial_state=None, load_state=None):
        if initial_state:
            self.state = self.copy_state(initial_state)
        elif load_state:
            with open(load_state, 'rb') as fh:
                self.state = pickle.load(fh)
        else:
            raise ValueError('No valid values supplied for neither \
            initial_state nor load_state')

To start annealing, I think only two things are required in __init__().
First, either initial_state or load_state is given.
Second, the given object is copyable. The definition of "copyable" can be custmized by overriding copy_state().

Therefore, all we have to do in __init__() is to check whether initial_state is given or not.
Other conditions about state can be handled by move() and energey(), so it doesn't matter if initial_state itself is evaluated as false like an empty list.

@perrygeo
Copy link
Owner

fixed by #20

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

No branches or pull requests

2 participants