Example #1
0
    def _execute_operations(
        self,
        container_id: str,
        container_type: ContainerType,
        operations: List[Operation],
    ) -> List[MetadataInconsistency]:
        kwargs = {
            "experimentId": container_id,
            "operations": [
                {
                    "path": path_to_str(op.path),
                    OperationApiNameVisitor()
                    .visit(op): OperationApiObjectConverter()
                    .convert(op),
                }
                for op in operations
            ],
            **DEFAULT_REQUEST_KWARGS,
        }

        try:
            result = (
                self.leaderboard_client.api.executeOperations(**kwargs)
                .response()
                .result
            )
            return [MetadataInconsistency(err.errorDescription) for err in result]
        except HTTPNotFound as e:
            raise_container_not_found(container_id, container_type, from_exception=e)
        except (HTTPPaymentRequired, HTTPUnprocessableEntity) as e:
            raise NeptuneLimitExceedException(
                reason=e.response.json().get("title", "Unknown reason")
            ) from e
Example #2
0
 def ping(self, container_id: str, container_type: ContainerType):
     request_kwargs = {
         "_request_options": {
             "timeout": 10,
             "connect_timeout": 10,
         }
     }
     try:
         self.leaderboard_client.api.ping(
             experimentId=container_id,
             **request_kwargs,
         ).response().result
     except HTTPNotFound as e:
         raise_container_not_found(container_id, container_type, from_exception=e)
Example #3
0
    def get_attributes(
        self, container_id: str, container_type: ContainerType
    ) -> List[Attribute]:
        def to_attribute(attr) -> Attribute:
            return Attribute(attr.name, AttributeType(attr.type))

        params = {
            "experimentId": container_id,
            **DEFAULT_REQUEST_KWARGS,
        }
        try:
            run = (
                self.leaderboard_client.api.getExperimentAttributes(**params)
                .response()
                .result
            )

            attribute_type_names = [at.value for at in AttributeType]
            accepted_attributes = [
                attr for attr in run.attributes if attr.type in attribute_type_names
            ]

            # Notify about ignored attrs
            ignored_attributes = set(attr.type for attr in run.attributes) - set(
                attr.type for attr in accepted_attributes
            )
            if ignored_attributes:
                _logger.warning(
                    "Ignored following attributes (unknown type): %s.\n"
                    "Try to upgrade `neptune-client.",
                    ignored_attributes,
                )

            return [
                to_attribute(attr)
                for attr in accepted_attributes
                if attr.type in attribute_type_names
            ]
        except HTTPNotFound as e:
            raise_container_not_found(
                container_id=container_id,
                container_type=container_type,
                from_exception=e,
            )
Example #4
0
 def fetch_atom_attribute_values(
     self, container_id: str, container_type: ContainerType, path: List[str]
 ) -> List[Tuple[str, AttributeType, Any]]:
     params = {
         "experimentId": container_id,
     }
     try:
         namespace_prefix = path_to_str(path)
         if namespace_prefix:
             # don't want to catch "ns/attribute/other" while looking for "ns/attr"
             namespace_prefix += "/"
         result = (
             self.leaderboard_client.api.getExperimentAttributes(**params)
             .response()
             .result
         )
         return [
             (attr.name, attr.type, map_attribute_result_to_value(attr))
             for attr in result.attributes
             if attr.name.startswith(namespace_prefix)
         ]
     except HTTPNotFound as e:
         raise_container_not_found(container_id, container_type, from_exception=e)
Example #5
0
 def _get_container(self, container_id: str, container_type: ContainerType):
     key = (container_id, container_type)
     if key not in self._containers:
         raise_container_not_found(container_id, container_type)
     container = self._containers[(container_id, container_type)]
     return container