-
-
Notifications
You must be signed in to change notification settings - Fork 985
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
Add Study.study_name #157
Add Study.study_name #157
Changes from 13 commits
8c65be2
cbd26db
21de4e0
45aa758
89030d5
dd4951a
b927a20
751fd5b
f2f8ae7
00d679f
8787c6f
bc2e58a
b11925f
cf1d89d
55441c4
2eca0af
5163fc5
82614b8
dab3061
eb1bd2f
6037645
dfb05b3
11c8975
728f45d
d0202c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,14 +44,16 @@ def get_parser(self, prog_name): | |
# type: (str) -> ArgumentParser | ||
|
||
parser = super(CreateStudy, self).get_parser(prog_name) | ||
parser.add_argument('--study_name', default=None, | ||
help='A human-readable name of a study to distinguish it from others.') | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
# type: (Namespace) -> None | ||
|
||
storage_url = get_storage_url(self.app_args.storage, self.app_args.config) | ||
storage = pfnopt.storages.RDBStorage(storage_url) | ||
study_uuid = pfnopt.create_study(storage).study_uuid | ||
study_uuid = pfnopt.create_study(storage, study_name=parsed_args.study_name).study_uuid | ||
print(study_uuid) | ||
|
||
|
||
|
@@ -79,7 +81,7 @@ def take_action(self, parsed_args): | |
class Studies(Lister): | ||
|
||
_datetime_format = '%Y-%m-%d %H:%M:%S' | ||
_study_list_header = ('UUID', 'TASK', 'N_TRIALS', 'DATETIME_START') | ||
_study_list_header = ('UUID', 'NAME', 'TASK', 'N_TRIALS', 'DATETIME_START') | ||
|
||
def get_parser(self, prog_name): | ||
# type: (str) -> ArgumentParser | ||
|
@@ -95,9 +97,10 @@ def take_action(self, parsed_args): | |
|
||
rows = [] | ||
for s in summaries: | ||
study_name = '' if s.study_name is None else s.study_name | ||
start = s.datetime_start.strftime(self._datetime_format) \ | ||
if s.datetime_start is not None else None | ||
row = (s.study_uuid, s.task.name, s.n_trials, start) | ||
row = (s.study_uuid, study_name, s.task.name, s.n_trials, start) | ||
rows.append(row) | ||
|
||
return self._study_list_header, tuple(rows) | ||
|
@@ -145,6 +148,8 @@ def get_parser(self, prog_name): | |
'number is set to CPU counts.') | ||
parser.add_argument('--study', help='Study UUID.') | ||
parser.add_argument('--create-study', action='store_true', help='Create a new study.') | ||
parser.add_argument('--study_name', default=None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also fixed this one. Thanks. |
||
help='A human-readable name of a study to distinguish it from others.') | ||
parser.add_argument('file', | ||
help='Python script file where the objective function resides.') | ||
parser.add_argument('method', help='The method name of the objective function.') | ||
|
@@ -162,7 +167,7 @@ def take_action(self, parsed_args): | |
|
||
storage_url = get_storage_url(self.app_args.storage, self.app_args.config) | ||
if parsed_args.create_study: | ||
study = pfnopt.create_study(storage=storage_url) | ||
study = pfnopt.create_study(storage=storage_url, study_name=parsed_args.study_name) | ||
else: | ||
study = pfnopt.Study(storage=storage_url, study_uuid=parsed_args.study) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
from pfnopt import distributions # NOQA | ||
from pfnopt.storages import base | ||
from pfnopt.storages.base import DEFAULT_STUDY_NAME_PREFIX | ||
from pfnopt import structs | ||
|
||
|
||
|
@@ -23,6 +24,7 @@ def __init__(self): | |
self.param_distribution = {} # type: Dict[str, distributions.BaseDistribution] | ||
self.task = structs.StudyTask.NOT_SET | ||
self.study_user_attrs = {} # type: Dict[str, Any] | ||
self.study_name = DEFAULT_STUDY_NAME_PREFIX + IN_MEMORY_STORAGE_STUDY_UUID # type: str | ||
|
||
self._lock = threading.Lock() | ||
|
||
|
@@ -37,8 +39,11 @@ def __setstate__(self, state): | |
self.__dict__.update(state) | ||
self._lock = threading.Lock() | ||
|
||
def create_new_study_id(self): | ||
# type: () -> int | ||
def create_new_study_id(self, study_name=None): | ||
# type: (Optional[str]) -> int | ||
|
||
if study_name is not None: | ||
self.study_name = study_name | ||
|
||
self.study_user_attrs[base.SYSTEM_ATTRS_KEY] = {} | ||
|
||
|
@@ -71,6 +76,22 @@ def get_study_uuid_from_id(self, study_id): | |
self._check_study_id(study_id) | ||
return IN_MEMORY_STORAGE_STUDY_UUID | ||
|
||
def get_study_id_from_name(self, study_name): | ||
# type: (str) -> int | ||
|
||
if study_name is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you. This none-value checking was removed. Thank you for your comment. |
||
raise ValueError("study_name is supposed to be str, not None.") | ||
if study_name != self.study_name: | ||
raise ValueError("No such study {}.".format(study_name)) | ||
|
||
return IN_MEMORY_STORAGE_STUDY_ID | ||
|
||
def get_study_name_from_id(self, study_id): | ||
# type: (int) -> str | ||
|
||
self._check_study_id(study_id) | ||
return self.study_name | ||
|
||
def get_study_task(self, study_id): | ||
# type: (int) -> structs.StudyTask | ||
|
||
|
@@ -97,6 +118,7 @@ def get_all_study_summaries(self): | |
return [structs.StudySummary( | ||
study_id=IN_MEMORY_STORAGE_STUDY_ID, | ||
study_uuid=IN_MEMORY_STORAGE_STUDY_UUID, | ||
study_name=self.study_name, | ||
task=self.task, | ||
best_trial=best_trial, | ||
user_attrs=copy.deepcopy(self.study_user_attrs), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep consistency, please use
-
instead of_
for argument name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment.
--study_name
was replaced with--study-name
to keep the consistency with other arguments.