# Path: vizier/pyvizier/shared/trial.py
# class ParameterExternalType(enum.IntEnum):
# class TrialStatus(enum.IntEnum):
# class Metric:
# class ParameterValue:
# class _MetricDict(collections.UserDict):
# class Measurement:
# class ParameterDict(cabc.MutableMapping):
# class Trial:
# class TrialSuggestion:
#   AS_INTERNAL = 0
#   AS_BOOLEAN = 1
#   AS_INTEGER = 2
#   AS_FLOAT = 3
#   UNKNOWN = 0
#   REQUESTED = 1
#   PENDING = 2
#   COMPLETED = 4
#   DELETED = 5
#   STOPPING = 6
#   def _std_not_negative(self, _, stddev):
#   def cast(
#       self,
#       external_type: ParameterExternalType,
#   ) -> ParameterValueTypes:
#   def as_float(self) -> Optional[float]:
#   def as_int(self) -> Optional[int]:
#   def as_str(self) -> Optional[str]:
#   def as_bool(self) -> Optional[bool]:
#   def __str__(self) -> str:
#   def __repr__(self) -> str:
#   def __setitem__(self, key: str, value: Union[float, Metric]):
#   def _value_is_finite(self, _, value):
# def _to_local_time(
#     dt: Optional[datetime.datetime]) -> Optional[datetime.datetime]:
#   def __init__(self, iterable: Any = tuple(), **kwargs):
#   def __setitem__(self, key: str, value: Union[ParameterValue,
#                                                ParameterValueTypes]):
#   def __delitem__(self, key: str):
#   def __getitem__(self, key: str) -> ParameterValue:
#   def __len__(self) -> int:
#   def __iter__(self):
#   def get_value(
#       self,
#       key: str,
#       default: Optional[ParameterValueTypes] = None
#   ) -> Optional[ParameterValueTypes]:
#   def duration(self) -> Optional[datetime.timedelta]:
#   def is_completed(self) -> bool:
#   def infeasible(self) -> bool:
#   def infeasibility_reason(self) -> Optional[str]:
#   def complete(self,
#                measurement: Measurement,
#                *,
#                inplace: bool = True) -> 'Trial':
#   def to_trial(self, uid: int) -> Trial:


import copy
import datetime
import numpy as np
from vizier.pyvizier.shared import trial
from absl.testing import absltest
from absl.testing import parameterized
    """Complete with inplace=False."""
    test = trial.Trial(status=trial.TrialStatus.PENDING)
    measurement = Measurement(metrics={
        'pr-auc': Metric(value=0.8),
        'latency': Metric(value=32)
    })

    test_copy = copy.deepcopy(test)

    completed = test.complete(measurement, inplace=False)

    # The returned Trial is completed.
    self.assertEqual(completed.final_measurement, measurement)
    self.assertGreaterEqual(completed.completion_time, completed.creation_time)
    self.assertLessEqual(completed.completion_time,
                         datetime.datetime.now().astimezone())
    self.assertGreaterEqual(completed.duration.total_seconds(), 0)
    self.assertEqual(completed.status, trial.TrialStatus.COMPLETED)
    self.assertTrue(completed.is_completed)

    # The original Trial is unchanged.
    self.assertEqual(test_copy, test)
    self.assertIsNone(test.final_measurement)
    self.assertIsNone(test.completion_time)
    self.assertIsNone(test.duration)
    self.assertEqual(test.status, trial.TrialStatus.PENDING)
    self.assertFalse(test.is_completed)

  def testDefaultsNotShared(self):
    """Make sure default parameters are not shared between instances."""

# Path: vizier/pyvizier/shared/trial.py
# class ParameterExternalType(enum.IntEnum):
# class TrialStatus(enum.IntEnum):
# class Metric:
# class ParameterValue:
# class _MetricDict(collections.UserDict):
# class Measurement:
# class ParameterDict(cabc.MutableMapping):
# class Trial:
# class TrialSuggestion:
#   AS_INTERNAL = 0
#   AS_BOOLEAN = 1
#   AS_INTEGER = 2
#   AS_FLOAT = 3
#   UNKNOWN = 0
#   REQUESTED = 1
#   PENDING = 2
#   COMPLETED = 4
#   DELETED = 5
#   STOPPING = 6
#   def _std_not_negative(self, _, stddev):
#   def cast(
#       self,
#       external_type: ParameterExternalType,
#   ) -> ParameterValueTypes:
#   def as_float(self) -> Optional[float]:
#   def as_int(self) -> Optional[int]:
#   def as_str(self) -> Optional[str]:
#   def as_bool(self) -> Optional[bool]:
#   def __str__(self) -> str:
#   def __repr__(self) -> str:
#   def __setitem__(self, key: str, value: Union[float, Metric]):
#   def _value_is_finite(self, _, value):
# def _to_local_time(
#     dt: Optional[datetime.datetime]) -> Optional[datetime.datetime]:
#   def __init__(self, iterable: Any = tuple(), **kwargs):
#   def __setitem__(self, key: str, value: Union[ParameterValue,
#                                                ParameterValueTypes]):
#   def __delitem__(self, key: str):
#   def __getitem__(self, key: str) -> ParameterValue:
#   def __len__(self) -> int:
#   def __iter__(self):
#   def get_value(
#       self,
#       key: str,
#       default: Optional[ParameterValueTypes] = None
#   ) -> Optional[ParameterValueTypes]:
#   def duration(self) -> Optional[datetime.timedelta]:
#   def is_completed(self) -> bool:
#   def infeasible(self) -> bool:
#   def infeasibility_reason(self) -> Optional[str]:
#   def complete(self,
#                measurement: Measurement,
#                *,
#                inplace: bool = True) -> 'Trial':
#   def to_trial(self, uid: int) -> Trial:


# Path: vizier/pyvizier/shared/trial_test.py
import copy
import datetime
import numpy as np
from vizier.pyvizier.shared import trial
from absl.testing import absltest
from absl.testing import parameterized

    """Complete with inplace=False."""
    test = trial.Trial(status=trial.TrialStatus.PENDING)
    measurement = Measurement(metrics={
        'pr-auc': Metric(value=0.8),
        'latency': Metric(value=32)
    })

    test_copy = copy.deepcopy(test)

    completed = test.complete(measurement, inplace=False)

    # The returned Trial is completed.
    self.assertEqual(completed.final_measurement, measurement)
    self.assertGreaterEqual(completed.completion_time, completed.creation_time)
    self.assertLessEqual(completed.completion_time,
                         datetime.datetime.now().astimezone())
    self.assertGreaterEqual(completed.duration.total_seconds(), 0)
    self.assertEqual(completed.status, trial.TrialStatus.COMPLETED)
    self.assertTrue(completed.is_completed)

    # The original Trial is unchanged.
    self.assertEqual(test_copy, test)
    self.assertIsNone(test.final_measurement)
    self.assertIsNone(test.completion_time)
    self.assertIsNone(test.duration)
    self.assertEqual(test.status, trial.TrialStatus.PENDING)
    self.assertFalse(test.is_completed)

  def testDefaultsNotShared(self):
    """Make sure default parameters are not shared between instances."""

    trial1 = trial.Trial()