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

Make FiniteDifferenceHvp pickleable #745

Merged
merged 2 commits into from Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/tf/cluster_demo.py
Expand Up @@ -39,7 +39,7 @@ def run_task(v):
baseline=baseline,
max_path_length=100,
discount=0.99,
step_size=v['step_size'],
max_kl_step=v['step_size'],
)

runner.setup(algo=algo, env=env)
Expand Down
2 changes: 1 addition & 1 deletion examples/tf/cluster_gym_mujoco_demo.py
Expand Up @@ -40,7 +40,7 @@ def run_task(vv):
baseline=baseline,
max_path_length=100,
discount=0.99,
step_size=vv['step_size'],
max_kl_step=vv['step_size'],
)

runner.setup(algo=algo, env=env)
Expand Down
2 changes: 1 addition & 1 deletion examples/tf/trpo_swimmer.py
Expand Up @@ -22,7 +22,7 @@ def run_task(*_):
baseline=baseline,
max_path_length=500,
discount=0.99,
step_size=0.01)
max_kl_step=0.01)

runner.setup(algo, env)
runner.train(n_epochs=40, batch_size=4000)
Expand Down
10 changes: 10 additions & 0 deletions src/garage/tf/optimizers/conjugate_gradient_optimizer.py
Expand Up @@ -133,6 +133,16 @@ def eval(x):

return eval

def __getstate__(self):
"""Object.__getstate__."""
new_dict = self.__dict__.copy()
del new_dict['opt_fun']
return new_dict

def __setstate__(self, state):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to re-create opt_fun here?
If you don't, then you should be able to delete this __setstate__ implementation, since this is the "default."
Note that you'll still have a __getstate__ implementation then, despite not having a __setstate__ implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, will remove __getstate__ since opt_fun is recreated somewhere else.

"""Object.__setstate__."""
self.__dict__.update(state)


class ConjugateGradientOptimizer(Serializable):
"""Performs constrained optimization via line search.
Expand Down