Skip to content

Commit

Permalink
Internal
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 528537828
  • Loading branch information
vizier-team authored and copybara-github committed May 2, 2023
1 parent 70afaad commit 49370b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions vizier/_src/pyvizier/shared/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,13 @@ class Trial(TrialSuggestion):

creation_time: Optional[datetime.datetime] = attr.ib(
init=True,
default=datetime.datetime.now(),
factory=datetime.datetime.now,
converter=_to_local_time,
kw_only=True,
repr=lambda v: v.strftime('%x %X') if v is not None else 'None',
validator=attr.validators.optional(
attr.validators.instance_of(datetime.datetime)),
attr.validators.instance_of(datetime.datetime)
),
)

completion_time: Optional[datetime.datetime] = attr.ib(
Expand Down
5 changes: 5 additions & 0 deletions vizier/_src/pyvizier/shared/trial_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ def testDefaultsNotShared(self):
trial1.parameters['x1'] = trial.ParameterValue(5)
self.assertEmpty(trial2.parameters)

def testCreationTime(self):
trial1 = trial.Trial()
trial2 = trial.Trial()
self.assertGreater(trial2.creation_time, trial1.creation_time)


class ParameterDictTest(parameterized.TestCase):

Expand Down
4 changes: 4 additions & 0 deletions vizier/pyvizier/converters/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def test_parameters_and_labels(self):
final_measurement=pyvizier.Measurement(
steps=1, metrics={'y1': 10.0, 'y2': 20.0}
),
creation_time=None,
),
pyvizier.Trial(
parameters={
Expand All @@ -349,9 +350,12 @@ def test_parameters_and_labels(self):
final_measurement=pyvizier.Measurement(
steps=1, metrics={'y1': 40.0, 'y2': 50.0, 'y3': 60.0}
),
creation_time=None,
),
]
trials = converter.to_trials(actual_features, actual_labels)
for t in trials:
t.creation_time = None
self.assertEqual(
actual_trials,
trials,
Expand Down

0 comments on commit 49370b9

Please sign in to comment.