Ejemplo n.º 1
0
 def _get_log_operations_from_value(self, value: Val, step: Optional[float],
                                    timestamp: float) -> List[Operation]:
     values = [
         LogFloats.ValueType(val, step=step, ts=timestamp)
         for val in value.values
     ]
     return [
         LogFloats(self._path, chunk)
         for chunk in split_to_chunks(values, 100)
     ]
Ejemplo n.º 2
0
    def test_log_with_timestamp(self):
        value_step_and_expected = [
            (13, 5.3, LogFloats.ValueType(13, None, 5.3)),
            (15.3, 10, LogFloats.ValueType(15.3, None, 10)),
        ]

        for value, ts, expected in value_step_and_expected:
            processor = MagicMock()
            exp, path, wait = (
                self._create_run(processor),
                self._random_path(),
                self._random_wait(),
            )
            var = FloatSeries(exp, path)
            var.log(value, timestamp=ts, wait=wait)
            processor.enqueue_operation.assert_called_once_with(
                LogFloats(path, [expected]), wait
            )
Ejemplo n.º 3
0
 def visit_log_floats(self, op: LogFloats) -> None:
     self._process_modify_op(
         _DataType.FLOAT_SERIES,
         op,
         self._log_modifier(
             LogFloats,
             ClearFloatLog,
             lambda op1, op2: LogFloats(op1.path, op1.values + op2.values),
         ),
     )
Ejemplo n.º 4
0
    def test_assign(self):
        value = FloatSeriesVal([17, 3.6], min=0, max=100, unit="%")
        expected = [
            LogFloats.ValueType(17, None, self._now()),
            LogFloats.ValueType(3.6, None, self._now()),
        ]

        processor = MagicMock()
        exp, path, wait = (
            self._create_run(processor),
            self._random_path(),
            self._random_wait(),
        )
        var = FloatSeries(exp, path)
        var.assign(value, wait=wait)
        self.assertEqual(3, processor.enqueue_operation.call_count)
        processor.enqueue_operation.assert_has_calls(
            [
                call(ConfigFloatSeries(path, min=0, max=100, unit="%"), False),
                call(ClearFloatLog(path), False),
                call(LogFloats(path, expected), wait),
            ]
        )
Ejemplo n.º 5
0
 def send_hardware_metric_reports(self, experiment, metrics,
                                  metric_reports):
     operations = []
     metrics_by_name = {metric.name: metric for metric in metrics}
     for report in metric_reports:
         metric = metrics_by_name.get(report.metric.name)
         gauges_count = len(metric.gauges)
         for gauge_name, metric_values in groupby(
                 report.values, lambda value: value.gauge_name):
             metric_values = list(metric_values)
             path = parse_path(
                 self._get_attribute_name_for_metric(
                     metric.resource_type, gauge_name, gauges_count))
             operations.append(
                 LogFloats(
                     path,
                     [
                         LogFloats.ValueType(
                             value.value, step=None, ts=value.timestamp)
                         for value in metric_values
                     ],
                 ))
     self._execute_operations(experiment, operations)
Ejemplo n.º 6
0
    def test_limit_exceed_legacy(self, swagger_client_factory):
        # given
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)
        backend = HostedNeptuneBackend(credentials)
        container_uuid = str(uuid.uuid4())

        # when:
        error = MagicMock()
        error.json.return_value = {"title": "Monitoring hours not left"}
        swagger_client.api.executeOperations.side_effect = HTTPUnprocessableEntity(
            response=error
        )

        # then:
        for container_type in self.container_types:
            with self.subTest(msg=f"For type {container_type.value}"):
                with self.assertRaises(NeptuneLimitExceedException):
                    backend.execute_operations(
                        container_id=container_uuid,
                        container_type=container_type,
                        operations=[
                            LogFloats(["float1"], [LogFloats.ValueType(1, 2, 3)]),
                        ],
                    )
Ejemplo n.º 7
0
    def test_get_float_series_values(self):
        # given
        for container_id, container_type in self.ids_with_types:
            with self.subTest(f"For containerType: {container_type}"):
                self.backend.execute_operations(
                    container_id,
                    container_type,
                    [
                        LogFloats(
                            ["x"],
                            [
                                LogFloats.ValueType(5, None, time()),
                                LogFloats.ValueType(3, None, time()),
                            ],
                        )
                    ],
                )
                self.backend.execute_operations(
                    container_id,
                    container_type,
                    [
                        LogFloats(
                            ["x"],
                            [
                                LogFloats.ValueType(2, None, time()),
                                LogFloats.ValueType(9, None, time()),
                            ],
                        )
                    ],
                )

                # when
                ret = self.backend.get_float_series_values(container_id,
                                                           container_type,
                                                           path=["x"],
                                                           limit=100,
                                                           offset=0)

                # then
                self.assertEqual(
                    FloatSeriesValues(
                        4,
                        [
                            FloatPointValue(
                                timestampMillis=42342, step=0, value=5),
                            FloatPointValue(
                                timestampMillis=42342, step=1, value=3),
                            FloatPointValue(
                                timestampMillis=42342, step=2, value=2),
                            FloatPointValue(
                                timestampMillis=42342, step=3, value=9),
                        ],
                    ),
                    ret,
                )
Ejemplo n.º 8
0
    def test_log_with_step(self):
        value_step_and_expected = [
            (13, 5.3, LogFloats.ValueType(13, 5.3, self._now())),
            (15.3, 10, LogFloats.ValueType(15.3, 10, self._now())),
            ([13], 5.3, LogFloats.ValueType(13, 5.3, self._now())),
            ((13,), 5.3, LogFloats.ValueType(13, 5.3, self._now())),
            ({13}, 5.3, LogFloats.ValueType(13, 5.3, self._now())),
        ]

        for value, step, expected in value_step_and_expected:
            processor = MagicMock()
            exp, path, wait = (
                self._create_run(processor),
                self._random_path(),
                self._random_wait(),
            )
            var = FloatSeries(exp, path)
            var.log(value, step=step, wait=wait)
            processor.enqueue_operation.assert_called_once_with(
                LogFloats(path, [expected]), wait
            )
Ejemplo n.º 9
0
    def test_get_float_series_attribute(self):
        # given
        for container_id, container_type in self.ids_with_types:
            with self.subTest(f"For containerType: {container_type}"):
                self.backend.execute_operations(
                    container_id,
                    container_type,
                    [
                        LogFloats(
                            ["x"],
                            [
                                LogFloats.ValueType(5, None, time()),
                                LogFloats.ValueType(3, None, time()),
                            ],
                        )
                    ],
                )
                self.backend.execute_operations(
                    container_id,
                    container_type,
                    [
                        LogFloats(
                            ["x"],
                            [
                                LogFloats.ValueType(2, None, time()),
                                LogFloats.ValueType(9, None, time()),
                            ],
                        )
                    ],
                )

                # when
                ret = self.backend.get_float_series_attribute(
                    container_id, container_type, ["x"])

                # then
                self.assertEqual(FloatSeriesAttribute(9), ret)
Ejemplo n.º 10
0
    def test_series(self):
        # given
        processor = OperationsPreprocessor()

        # when
        processor.process([
            LogFloats(["a"], [FLog(1, 2, 3)]),
            ConfigFloatSeries(["a"], min=7, max=70, unit="%"),
            DeleteAttribute(["a"]),
            LogStrings(["a"], [SLog("111", 3, 4)]),
            DeleteAttribute(["b"]),
            LogStrings(["b"], [SLog("222", None, 6)]),
            LogFloats(["c"], [FLog(1, 2, 3)]),
            LogFloats(["c"],
                      [FLog(10, 20, 30), FLog(100, 200, 300)]),
            LogStrings(["d"], [SLog("4", 111, 222)]),
            ClearFloatLog(["e"]),
            LogImages(["f"], [ILog("1", 2, 3)]),
            LogImages(
                ["f"],
                [ILog("10", 20, 30), FLog("100", 200, 300)]),
            LogImages(["f"], [ILog("1", 2, 3)]),
            LogImages(
                ["f"],
                [ILog("10", 20, 30), FLog("100", 200, 300)]),
            ClearImageLog(["f"]),
            LogImages(
                ["f"],
                [ILog("3", 20, 30), FLog("4", 200, 300)]),
            LogImages(["f"], [ILog("5", 2, 3)]),
            LogImages(
                ["f"],
                [ILog("8", 20, 30), FLog("1000", 200, 300)]),
            LogImages(
                ["g"],
                [ILog("10", 20, 30), FLog("100", 200, 300)]),
            ClearImageLog(["g"]),
            AssignString(["h"], "44"),
            LogFloats(["h"],
                      [FLog(10, 20, 30), FLog(100, 200, 300)]),
            LogFloats(["i"], [FLog(1, 2, 3)]),
            ConfigFloatSeries(["i"], min=7, max=70, unit="%"),
            ClearFloatLog(["i"]),
            LogFloats(["i"],
                      [FLog(10, 20, 30), FLog(100, 200, 300)]),
        ])

        # then
        self.assertEqual(
            processor.get_operations(),
            [
                LogFloats(["a"], [FLog(1, 2, 3)]),
                DeleteAttribute(["a"]),
                LogStrings(["a"], [FLog("111", 3, 4)]),
                DeleteAttribute(["b"]),
                LogStrings(["b"], [SLog("222", None, 6)]),
                LogFloats(
                    ["c"],
                    [FLog(1, 2, 3),
                     FLog(10, 20, 30),
                     FLog(100, 200, 300)]),
                LogStrings(["d"], [SLog("4", 111, 222)]),
                ClearFloatLog(["e"]),
                ClearImageLog(["f"]),
                LogImages(
                    ["f"],
                    [
                        ILog("3", 20, 30),
                        FLog("4", 200, 300),
                        ILog("5", 2, 3),
                        ILog("8", 20, 30),
                        FLog("1000", 200, 300),
                    ],
                ),
                ClearImageLog(["g"]),
                AssignString(["h"], "44"),
                ClearFloatLog(["i"]),
                LogFloats(["i"], [FLog(10, 20, 30),
                                  FLog(100, 200, 300)]),
                ConfigFloatSeries(["i"], min=7, max=70, unit="%"),
            ],
        )
        self.assertEqual(
            processor.get_errors(),
            [
                MetadataInconsistency(
                    "Cannot perform LogFloats operation on h: Attribute is not a Float Series"
                )
            ],
        )
Ejemplo n.º 11
0
    def test_execute_operations(self, upload_mock, swagger_client_factory):
        # given
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)
        backend = HostedNeptuneBackend(credentials)
        container_uuid = str(uuid.uuid4())

        response_error = MagicMock()
        response_error.errorDescription = "error1"
        swagger_client.api.executeOperations().response().result = [response_error]
        swagger_client.api.executeOperations.reset_mock()
        upload_mock.return_value = [FileUploadError("file1", "error2")]
        some_text = "Some streamed text"
        some_binary = b"Some streamed binary"

        for container_type in self.container_types:
            with self.subTest(msg=f"For type {container_type.value}"):
                upload_mock.reset_mock()
                swagger_client_factory.reset_mock()

                # when
                result = backend.execute_operations(
                    container_id=container_uuid,
                    container_type=container_type,
                    operations=[
                        UploadFile(
                            path=["some", "files", "some_file"],
                            ext="",
                            file_path="path_to_file",
                        ),
                        UploadFileContent(
                            path=["some", "files", "some_text_stream"],
                            ext="txt",
                            file_content=base64_encode(some_text.encode("utf-8")),
                        ),
                        UploadFileContent(
                            path=["some", "files", "some_binary_stream"],
                            ext="bin",
                            file_content=base64_encode(some_binary),
                        ),
                        LogFloats(["images", "img1"], [LogFloats.ValueType(1, 2, 3)]),
                        AssignString(["properties", "name"], "some text"),
                        UploadFile(
                            path=["some", "other", "file.txt"],
                            ext="txt",
                            file_path="other/file/path.txt",
                        ),
                    ],
                )

                # then
                swagger_client.api.executeOperations.assert_called_once_with(
                    **{
                        "experimentId": str(container_uuid),
                        "operations": [
                            {
                                "path": "images/img1",
                                "logFloats": {
                                    "entries": [
                                        {
                                            "value": 1,
                                            "step": 2,
                                            "timestampMilliseconds": 3000,
                                        }
                                    ]
                                },
                            },
                            {
                                "path": "properties/name",
                                "assignString": {"value": "some text"},
                            },
                        ],
                        **DEFAULT_REQUEST_KWARGS,
                    }
                )

                upload_mock.assert_has_calls(
                    [
                        call(
                            swagger_client=backend.leaderboard_client,
                            container_id=container_uuid,
                            attribute="some/other/file.txt",
                            source="other/file/path.txt",
                            ext="txt",
                            multipart_config=backend._client_config.multipart_config,
                        ),
                        call(
                            swagger_client=backend.leaderboard_client,
                            container_id=container_uuid,
                            attribute="some/files/some_file",
                            source="path_to_file",
                            ext="",
                            multipart_config=backend._client_config.multipart_config,
                        ),
                        call(
                            swagger_client=backend.leaderboard_client,
                            container_id=container_uuid,
                            attribute="some/files/some_text_stream",
                            source=some_text.encode("utf-8"),
                            ext="txt",
                            multipart_config=backend._client_config.multipart_config,
                        ),
                        call(
                            swagger_client=backend.leaderboard_client,
                            container_id=container_uuid,
                            attribute="some/files/some_binary_stream",
                            source=some_binary,
                            ext="bin",
                            multipart_config=backend._client_config.multipart_config,
                        ),
                    ],
                    any_order=True,
                )

                self.assertEqual(
                    (
                        6,
                        [
                            FileUploadError("file1", "error2"),
                            FileUploadError("file1", "error2"),
                            FileUploadError("file1", "error2"),
                            FileUploadError("file1", "error2"),
                            MetadataInconsistency("error1"),
                        ],
                    ),
                    result,
                )
Ejemplo n.º 12
0
    def test_log(self):
        value_and_expected = [
            (13, [LogFloats.ValueType(13, None, self._now())]),
            (15.3, [LogFloats.ValueType(15.3, None, self._now())]),
            (
                [1, 9, 7],
                [
                    LogFloats.ValueType(1, None, self._now()),
                    LogFloats.ValueType(9, None, self._now()),
                    LogFloats.ValueType(7, None, self._now()),
                ],
            ),
            (
                (1, 9, 7),
                [
                    LogFloats.ValueType(1, None, self._now()),
                    LogFloats.ValueType(9, None, self._now()),
                    LogFloats.ValueType(7, None, self._now()),
                ],
            ),
            (
                {1, 9, 7},
                [
                    LogFloats.ValueType(1, None, self._now()),
                    LogFloats.ValueType(9, None, self._now()),
                    LogFloats.ValueType(7, None, self._now()),
                ],
            ),
        ]

        for value, expected in value_and_expected:
            processor = MagicMock()
            exp, path, wait = (
                self._create_run(processor),
                self._random_path(),
                self._random_wait(),
            )
            var = FloatSeries(exp, path)
            var.log(value, wait=wait)
            processor.enqueue_operation.assert_called_once_with(
                LogFloats(path, expected), wait
            )