Skip to content

Commit

Permalink
Expand local_dir in Trial init (ray-project#2013)
Browse files Browse the repository at this point in the history
* Fix the case where Trial logs into wrong paths when `local_dir`
argument starts with tilde (~), by expanding the `local_dir` argument
* Add test case for checking that the tilde gets expanded
  • Loading branch information
hartikainen authored and richardliaw committed May 8, 2018
1 parent b1e32ca commit 2048b54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions python/ray/tune/test/trial_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@ def train(config, reporter):
}
})

def testLogdirStartingWithTilde(self):
local_dir = '~/ray_results/local_dir'

def train(config, reporter):
cwd = os.getcwd()
assert cwd.startswith(os.path.expanduser(local_dir)), cwd
assert not cwd.startswith('~'), cwd
reporter(timesteps_total=1)

register_trainable('f1', train)
run_experiments({
'foo': {
'run': 'f1',
'local_dir': local_dir,
'config': {
'a': 'b'
},
}
})

def testLongFilename(self):
def train(config, reporter):
assert "/tmp/logdir/foo" in os.getcwd(), os.getcwd()
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self,
# Trial config
self.trainable_name = trainable_name
self.config = config or {}
self.local_dir = local_dir
self.local_dir = os.path.expanduser(local_dir)
self.experiment_tag = experiment_tag
self.resources = (
resources
Expand Down

0 comments on commit 2048b54

Please sign in to comment.