Download tasks/format-code-task-001886.json from akseljoonas/mimo-openenv-software: direct link, hf CLI and curl.
- Browser
- Download file 12.2 kB
-
https://huggingface.co/datasets/akseljoonas/mimo-openenv-software/resolve/main/tasks/format-code-task-001886.json
- Command line
-
hf download hf://datasets/akseljoonas/mimo-openenv-software/tasks/format-code-task-001886.json
-
curl -L -o format-code-task-001886.json https://huggingface.co/datasets/akseljoonas/mimo-openenv-software/resolve/main/tasks/format-code-task-001886.json
12.2 kB
| {"cwd": "/workspace/repo", "dataset_type": "opensource-code", "docker_image": "format-code-task-001886:latest", "instance_id": "format-code-task-001886", "problem_statement": "I want libfmp.c3 to provide pure dynamic-time-warping helper functions for aligning two feature sequences. The public functions should be compute_cost_matrix(X: np.ndarray, Y: np.ndarray, metric: str = \"euclidean\") -> np.ndarray, compute_accumulated_cost_matrix(C: np.ndarray) -> np.ndarray, compute_optimal_warping_path(D: np.ndarray) -> np.ndarray, compute_accumulated_cost_matrix_21(C: np.ndarray) -> np.ndarray, and compute_optimal_warping_path_21(D: np.ndarray) -> np.ndarray.\n\nFor compute_cost_matrix(np.array([[0., 1., 3.]]), np.array([[0., 2.]])) with the default Euclidean metric, I expect np.array([[0., 2.], [1., 1.], [3., 1.]]). Passing an invalid SciPy distance metric such as metric=\"not_a_metric\" should raise ValueError. For the cost matrix np.array([[0., 2.], [1., 1.], [3., 1.]]), compute_accumulated_cost_matrix should return np.array([[0., 2.], [1., 1.], [4., 2.]]), and compute_optimal_warping_path on that accumulated matrix should return np.array([[0, 0], [1, 0], [2, 1]]).\n\nFor C = np.array([[1., 3., 4.], [2., 1., 3.], [3., 2., 1.], [4., 3., 2.]]), the standard accumulated cost matrix should be np.array([[1., 4., 8.], [3., 2., 5.], [6., 4., 3.], [10., 7., 5.]]), with optimal path np.array([[0, 0], [1, 1], [2, 2], [3, 2]]). For the same C, the constrained 2-1 variant should produce an accumulated matrix np.array([[1., np.inf, np.inf], [np.inf, 2., 4.], [np.inf, 3., 3.], [np.inf, np.inf, 4.]]) and a path np.array([[0, 0], [1, 1], [3, 2]]). Calling these functions repeatedly with the same arrays should give the same returned arrays, should not mutate the input arrays, and should not perform filesystem, network, or global-state side effects.", "test_command": "bash /workspace/repo/mimo_test_command.sh", "test_patch": "diff --git a/usercase-test-coderl/test_dtw_helpers.py b/usercase-test-coderl/test_dtw_helpers.py\nnew file mode 100644\n--- /dev/null\n+++ b/usercase-test-coderl/test_dtw_helpers.py\n@@ -0,0 +1,326 @@\n+\n+\n+\n+\n+\n+\n+import json\n+import os\n+import socket\n+import subprocess\n+import sys\n+import textwrap\n+\n+import numpy as np\n+import pytest\n+\n+from libfmp.c3 import (\n+ compute_accumulated_cost_matrix,\n+ compute_accumulated_cost_matrix_21,\n+ compute_cost_matrix,\n+ compute_optimal_warping_path,\n+ compute_optimal_warping_path_21,\n+)\n+\n+\n+def assert_array_exact(actual, expected):\n+ np.testing.assert_array_equal(actual, np.array(expected))\n+\n+\n+def assert_array_close(actual, expected):\n+ np.testing.assert_allclose(actual, np.array(expected), rtol=1e-8, atol=1e-10)\n+\n+\n+def test_cost_matrix_default_euclidean_one_feature_sequence():\n+\n+\n+\n+ X = np.array([[0.0, 1.0, 3.0]])\n+ Y = np.array([[0.0, 2.0]])\n+\n+ actual = compute_cost_matrix(X, Y)\n+\n+ assert_array_exact(actual, [[0.0, 2.0], [1.0, 1.0], [3.0, 1.0]])\n+\n+\n+def test_cost_matrix_default_euclidean_two_feature_sequence():\n+\n+\n+\n+ X = np.array([[0.0, 1.0, 3.0], [2.0, 2.0, -1.0]])\n+ Y = np.array([[1.0, 4.0], [2.0, -2.0]])\n+\n+ actual = compute_cost_matrix(X, Y)\n+\n+ assert_array_close(\n+ actual,\n+ [\n+ [1.0, 5.65685425],\n+ [0.0, 5.0],\n+ [3.60555128, 1.41421356],\n+ ],\n+ )\n+\n+\n+def test_cost_matrix_invalid_metric_raises_value_error():\n+\n+\n+\n+ X = np.array([[0.0, 1.0, 3.0]])\n+ Y = np.array([[0.0, 2.0]])\n+\n+\n+ with pytest.raises(ValueError):\n+ compute_cost_matrix(X, Y, metric=\"not_a_metric\")\n+\n+\n+def test_standard_accumulated_cost_matrix_from_three_by_two_costs():\n+\n+\n+\n+ C = np.array([[0.0, 2.0], [1.0, 1.0], [3.0, 1.0]])\n+\n+ actual = compute_accumulated_cost_matrix(C)\n+\n+ assert_array_exact(actual, [[0.0, 2.0], [1.0, 1.0], [4.0, 2.0]])\n+\n+\n+def test_standard_optimal_path_from_three_by_two_accumulated_costs():\n+\n+\n+\n+ D = np.array([[0.0, 2.0], [1.0, 1.0], [4.0, 2.0]])\n+\n+ actual = compute_optimal_warping_path(D)\n+\n+ assert_array_exact(actual, [[0, 0], [1, 0], [2, 1]])\n+\n+\n+def test_standard_accumulated_cost_matrix_from_four_by_three_costs():\n+\n+\n+\n+ C = np.array(\n+ [[1.0, 3.0, 4.0], [2.0, 1.0, 3.0], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]]\n+ )\n+\n+ actual = compute_accumulated_cost_matrix(C)\n+\n+ assert_array_exact(\n+ actual,\n+ [[1.0, 4.0, 8.0], [3.0, 2.0, 5.0], [6.0, 4.0, 3.0], [10.0, 7.0, 5.0]],\n+ )\n+\n+\n+def test_standard_optimal_path_from_four_by_three_accumulated_costs():\n+\n+\n+\n+ D = np.array(\n+ [[1.0, 4.0, 8.0], [3.0, 2.0, 5.0], [6.0, 4.0, 3.0], [10.0, 7.0, 5.0]]\n+ )\n+\n+ actual = compute_optimal_warping_path(D)\n+\n+ assert_array_exact(actual, [[0, 0], [1, 1], [2, 2], [3, 2]])\n+\n+\n+def test_constrained_21_accumulated_cost_matrix_from_four_by_three_costs():\n+\n+\n+\n+ C = np.array(\n+ [[1.0, 3.0, 4.0], [2.0, 1.0, 3.0], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]]\n+ )\n+\n+ actual = compute_accumulated_cost_matrix_21(C)\n+\n+ assert_array_exact(\n+ actual,\n+ [\n+ [1.0, np.inf, np.inf],\n+ [np.inf, 2.0, 4.0],\n+ [np.inf, 3.0, 3.0],\n+ [np.inf, np.inf, 4.0],\n+ ],\n+ )\n+\n+\n+def test_constrained_21_optimal_path_from_four_by_three_accumulated_costs():\n+\n+\n+\n+ D = np.array(\n+ [\n+ [1.0, np.inf, np.inf],\n+ [np.inf, 2.0, 4.0],\n+ [np.inf, 3.0, 3.0],\n+ [np.inf, np.inf, 4.0],\n+ ]\n+ )\n+\n+ actual = compute_optimal_warping_path_21(D)\n+\n+ assert_array_exact(actual, [[0, 0], [1, 1], [3, 2]])\n+\n+\n+def test_single_cell_accumulation_and_paths_are_identity_boundaries():\n+\n+\n+\n+ C = np.array([[2.5]])\n+\n+ D_standard = compute_accumulated_cost_matrix(C)\n+ P_standard = compute_optimal_warping_path(D_standard)\n+ D_21 = compute_accumulated_cost_matrix_21(C)\n+ P_21 = compute_optimal_warping_path_21(D_21)\n+\n+ assert_array_exact(D_standard, [[2.5]])\n+ assert_array_exact(P_standard, [[0, 0]])\n+ assert_array_exact(D_21, [[2.5]])\n+ assert_array_exact(P_21, [[0, 0]])\n+\n+\n+def test_referential_transparency_for_repeated_same_input():\n+ C = np.array(\n+ [[1.0, 3.0, 4.0], [2.0, 1.0, 3.0], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]]\n+ )\n+\n+ first_D = compute_accumulated_cost_matrix(C)\n+ second_D = compute_accumulated_cost_matrix(C)\n+ first_P = compute_optimal_warping_path(first_D)\n+ second_P = compute_optimal_warping_path(first_D)\n+\n+ assert_array_exact(second_D, first_D)\n+ assert_array_exact(second_P, first_P)\n+\n+\n+def test_dtw_helpers_do_not_mutate_caller_arrays():\n+ X = np.array([[0.0, 1.0, 3.0]])\n+ Y = np.array([[0.0, 2.0]])\n+ C = np.array(\n+ [[1.0, 3.0, 4.0], [2.0, 1.0, 3.0], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]]\n+ )\n+ D_standard = np.array(\n+ [[1.0, 4.0, 8.0], [3.0, 2.0, 5.0], [6.0, 4.0, 3.0], [10.0, 7.0, 5.0]]\n+ )\n+ D_21 = np.array(\n+ [\n+ [1.0, np.inf, np.inf],\n+ [np.inf, 2.0, 4.0],\n+ [np.inf, 3.0, 3.0],\n+ [np.inf, np.inf, 4.0],\n+ ]\n+ )\n+ originals = [array.copy() for array in (X, Y, C, D_standard, D_21)]\n+\n+ compute_cost_matrix(X, Y)\n+ compute_accumulated_cost_matrix(C)\n+ compute_accumulated_cost_matrix_21(C)\n+ compute_optimal_warping_path(D_standard)\n+ compute_optimal_warping_path_21(D_21)\n+\n+ for actual, expected in zip((X, Y, C, D_standard, D_21), originals):\n+ np.testing.assert_array_equal(actual, expected)\n+\n+\n+def test_no_global_state_matches_fresh_process_for_representative_calls():\n+ X = np.array([[0.0, 1.0, 3.0]])\n+ Y = np.array([[0.0, 2.0]])\n+ C = np.array(\n+ [[1.0, 3.0, 4.0], [2.0, 1.0, 3.0], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]]\n+ )\n+ D_standard = compute_accumulated_cost_matrix(C)\n+ D_21 = compute_accumulated_cost_matrix_21(C)\n+ in_process = {\n+ \"cost\": compute_cost_matrix(X, Y),\n+ \"acc\": D_standard,\n+ \"path\": compute_optimal_warping_path(D_standard),\n+ \"acc21\": D_21,\n+ \"path21\": compute_optimal_warping_path_21(D_21),\n+ }\n+\n+ compute_cost_matrix(np.array([[10.0, -1.0]]), np.array([[3.0]]))\n+ compute_accumulated_cost_matrix(np.array([[9.0, 8.0], [7.0, 6.0]]))\n+ compute_accumulated_cost_matrix_21(np.array([[9.0, 8.0], [7.0, 6.0]]))\n+\n+ after_noise = {\n+ \"cost\": compute_cost_matrix(X, Y),\n+ \"acc\": compute_accumulated_cost_matrix(C),\n+ \"path\": compute_optimal_warping_path(D_standard),\n+ \"acc21\": compute_accumulated_cost_matrix_21(C),\n+ \"path21\": compute_optimal_warping_path_21(D_21),\n+ }\n+ for key in in_process:\n+ np.testing.assert_array_equal(after_noise[key], in_process[key])\n+\n+ script = r\"\"\"\n+import json\n+import sys\n+sys.path.insert(0, \"/workspace/repo\")\n+import numpy as np\n+from libfmp.c3 import (\n+ compute_accumulated_cost_matrix,\n+ compute_accumulated_cost_matrix_21,\n+ compute_cost_matrix,\n+ compute_optimal_warping_path,\n+ compute_optimal_warping_path_21,\n+)\n+X = np.array([[0.0, 1.0, 3.0]])\n+Y = np.array([[0.0, 2.0]])\n+C = np.array([[1.0, 3.0, 4.0], [2.0, 1.0, 3.0], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]])\n+D_standard = compute_accumulated_cost_matrix(C)\n+D_21 = compute_accumulated_cost_matrix_21(C)\n+out = {\n+ \"cost\": compute_cost_matrix(X, Y).tolist(),\n+ \"acc\": D_standard.tolist(),\n+ \"path\": compute_optimal_warping_path(D_standard).tolist(),\n+ \"acc21\": D_21.tolist(),\n+ \"path21\": compute_optimal_warping_path_21(D_21).tolist(),\n+}\n+sys.stdout.write(json.dumps(out))\n+\"\"\"\n+ completed = subprocess.run(\n+ [sys.executable, \"-c\", textwrap.dedent(script)],\n+ check=True,\n+ stdout=subprocess.PIPE,\n+ stderr=subprocess.PIPE,\n+ text=True,\n+ )\n+ fresh_process = json.loads(completed.stdout)\n+\n+ for key, expected in in_process.items():\n+ np.testing.assert_array_equal(np.array(fresh_process[key]), expected)\n+\n+\n+def test_no_undeclared_filesystem_or_network_side_effects(monkeypatch, tmp_path):\n+ def blocked_socket(*args, **kwargs):\n+ raise AssertionError(\"network access is undeclared for DTW helpers\")\n+\n+ def snapshot_tree(root):\n+ return {\n+ path.relative_to(root).as_posix(): path.stat().st_size\n+ for path in root.rglob(\"*\")\n+ if path.is_file()\n+ }\n+\n+ monkeypatch.setattr(socket, \"socket\", blocked_socket)\n+ monkeypatch.chdir(tmp_path)\n+ before = snapshot_tree(tmp_path)\n+\n+ X = np.array([[0.0, 1.0, 3.0]])\n+ Y = np.array([[0.0, 2.0]])\n+ C = np.array([[0.0, 2.0], [1.0, 1.0], [3.0, 1.0]])\n+ D = compute_accumulated_cost_matrix(C)\n+ D_21 = compute_accumulated_cost_matrix_21(\n+ np.array(\n+ [[1.0, 3.0, 4.0], [2.0, 1.0, 3.0], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]]\n+ )\n+ )\n+\n+ compute_cost_matrix(X, Y)\n+ compute_optimal_warping_path(D)\n+ compute_optimal_warping_path_21(D_21)\n+\n+ after = snapshot_tree(tmp_path)\n+ assert after == before\ndiff --git a/mimo_test_command.sh b/mimo_test_command.sh\nnew file mode 100755\n--- /dev/null\n+++ b/mimo_test_command.sh\n@@ -0,0 +1,17 @@\n+#!/usr/bin/env bash\n+\n+\n+\n+\n+export NODE_OPTIONS=\"${NODE_OPTIONS:-} --max-old-space-size=4096\"\n+export MAVEN_OPTS=\"${MAVEN_OPTS:-} -Xmx3g -XX:+UseG1GC\"\n+export GRADLE_OPTS=\"${GRADLE_OPTS:-} -Xmx3g -XX:+UseG1GC\"\n+export TEST_JVM_OPTS=\"${TEST_JVM_OPTS:-} -Xmx3g\"\n+set -e\n+cd /workspace/repo\n+set -euo pipefail\n+cd /workspace/repo\n+export PYTHONPATH=\"/workspace/repo${PYTHONPATH:+:${PYTHONPATH}}\"\n+export PYTEST_DISABLE_PLUGIN_AUTOLOAD=1\n+export MPLBACKEND=Agg\n+exec /usr/local/bin/python -m pytest -p no:cacheprovider /workspace/repo/usercase-test-coderl/test_dtw_helpers.py -v\n", "verifier_timeout_sec": 1800} |