def _name_and_store_arm_if_not_exists(self, arm: Arm, proposed_name: str) -> None: """Tries to lookup arm with same signature, otherwise names and stores it. - Looks up if arm already exists on experiment - If so, name the input arm the same as the existing arm - else name the arm with given name and store in _arms_by_signature Args: arm: The arm object to name. proposed_name: The name to assign if it doesn't have one already. """ # If arm is identical to an existing arm, return that # so that the names match. if arm.signature in self.arms_by_signature: existing_arm = self.arms_by_signature[arm.signature] if arm.has_name: if arm.name != existing_arm.name: raise ValueError( f"Arm already exists with name {existing_arm.name}, " f"which doesn't match given arm name of {arm.name}.") else: arm.name = existing_arm.name else: if not arm.has_name: arm.name = proposed_name self._register_arm(arm)
def testNameValidation(self): arm = Arm(parameters={"y": 0.25, "x": 0.75, "z": 75}) self.assertFalse(arm.has_name) with self.assertRaises(ValueError): arm.name arm.name = "0_0" with self.assertRaises(ValueError): arm.name = "1_0"