jitterbug-inference 2.2.0__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/PKG-INFO +9 -1
  2. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/README.md +5 -0
  3. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/pyproject.toml +3 -1
  4. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/pyproject.toml.orig +4 -1
  5. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/analyzer.py +15 -3
  6. jitterbug_inference-2.3.0/src/jitterbug/io/compression.py +108 -0
  7. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/io/data_loader.py +15 -7
  8. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/io/exporters.py +26 -6
  9. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/__init__.py +0 -0
  10. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/analysis/__init__.py +0 -0
  11. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/analysis/clustering_analyzer.py +0 -0
  12. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/analysis/congestion_inference_analyzer.py +0 -0
  13. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/analysis/jitter_analyzer.py +0 -0
  14. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/analysis/latency_jump_analyzer.py +0 -0
  15. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/cli/__init__.py +0 -0
  16. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/cli/main.py +0 -0
  17. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/detection/__init__.py +0 -0
  18. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/detection/algorithms.py +0 -0
  19. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/detection/change_point_detector.py +0 -0
  20. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/io/__init__.py +0 -0
  21. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/models/__init__.py +0 -0
  22. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/models/analysis.py +0 -0
  23. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/models/config.py +0 -0
  24. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/models/rtt_data.py +0 -0
  25. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/py.typed +0 -0
  26. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/visualization/__init__.py +0 -0
  27. {jitterbug_inference-2.2.0 → jitterbug_inference-2.3.0}/src/jitterbug/visualization/plotter.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: jitterbug-inference
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Framework for jitter-based network congestion inference
5
5
  Keywords: network,congestion,rtt,jitter,analysis,changepoint,detection
6
6
  Author: Esteban Carisimo
@@ -32,6 +32,7 @@ Requires-Dist: bayesian-changepoint>=1.2 ; extra == 'all'
32
32
  Requires-Dist: torch>=2.0 ; extra == 'all'
33
33
  Requires-Dist: scikit-learn>=1.3 ; extra == 'all'
34
34
  Requires-Dist: influxdb-client>=1.30.0 ; extra == 'all'
35
+ Requires-Dist: zstandard>=0.23 ; python_full_version < '3.14' and extra == 'all'
35
36
  Requires-Dist: matplotlib>=3.5.0 ; extra == 'all'
36
37
  Requires-Dist: ipykernel>=6.0.0 ; extra == 'all'
37
38
  Requires-Dist: jupyter>=1.0.0 ; extra == 'all'
@@ -43,6 +44,7 @@ Requires-Dist: influxdb-client>=1.30.0 ; extra == 'influx'
43
44
  Requires-Dist: ipykernel>=6.0.0 ; extra == 'jupyter'
44
45
  Requires-Dist: jupyter>=1.0.0 ; extra == 'jupyter'
45
46
  Requires-Dist: matplotlib>=3.5.0 ; extra == 'visualization'
47
+ Requires-Dist: zstandard>=0.23 ; python_full_version < '3.14' and extra == 'zstd'
46
48
  Maintainer: Esteban Carisimo
47
49
  Maintainer-email: Esteban Carisimo <esteban.carisimo@northwestern.edu>
48
50
  Requires-Python: >=3.10
@@ -57,6 +59,7 @@ Provides-Extra: clustering
57
59
  Provides-Extra: influx
58
60
  Provides-Extra: jupyter
59
61
  Provides-Extra: visualization
62
+ Provides-Extra: zstd
60
63
  Description-Content-Type: text/markdown
61
64
 
62
65
  # 🐞 Jitterbug
@@ -115,6 +118,7 @@ See [docs/INSTALLATION.md](https://github.com/estcarisimo/jitterbug/blob/main/do
115
118
  | `bcp` | [bayesian-changepoint](https://pypi.org/project/bayesian-changepoint/) + torch | The Bayesian detector used in the paper |
116
119
  | `clustering` | scikit-learn | The non-sequential mode (`--mode clustering`) |
117
120
  | `influx` | influxdb-client | Loading RTTs straight from InfluxDB |
121
+ | `zstd` | zstandard (not needed on Python 3.14+) | Reading and writing `.zst`-compressed files |
118
122
  | `visualization` | matplotlib | `jitterbug visualize` and the plotting helpers |
119
123
  | `jupyter` | JupyterLab, ipykernel | The notebooks in `examples/` |
120
124
  | `all` | everything above | |
@@ -150,6 +154,10 @@ jitterbug analyze examples/network_analysis/data/raw.csv --summary-only
150
154
 
151
155
  # CSV instead of JSON (Parquet is also supported if `pyarrow` is installed)
152
156
  jitterbug analyze rtts.csv --output results.csv --output-format csv
157
+
158
+ # Zstandard-compressed input and output: a trailing .zst is enough (needs the `zstd` extra
159
+ # before Python 3.14)
160
+ jitterbug analyze rtts.csv.zst --output results.json.zst
153
161
  ```
154
162
 
155
163
  ### Validate input before analyzing
@@ -54,6 +54,7 @@ See [docs/INSTALLATION.md](https://github.com/estcarisimo/jitterbug/blob/main/do
54
54
  | `bcp` | [bayesian-changepoint](https://pypi.org/project/bayesian-changepoint/) + torch | The Bayesian detector used in the paper |
55
55
  | `clustering` | scikit-learn | The non-sequential mode (`--mode clustering`) |
56
56
  | `influx` | influxdb-client | Loading RTTs straight from InfluxDB |
57
+ | `zstd` | zstandard (not needed on Python 3.14+) | Reading and writing `.zst`-compressed files |
57
58
  | `visualization` | matplotlib | `jitterbug visualize` and the plotting helpers |
58
59
  | `jupyter` | JupyterLab, ipykernel | The notebooks in `examples/` |
59
60
  | `all` | everything above | |
@@ -89,6 +90,10 @@ jitterbug analyze examples/network_analysis/data/raw.csv --summary-only
89
90
 
90
91
  # CSV instead of JSON (Parquet is also supported if `pyarrow` is installed)
91
92
  jitterbug analyze rtts.csv --output results.csv --output-format csv
93
+
94
+ # Zstandard-compressed input and output: a trailing .zst is enough (needs the `zstd` extra
95
+ # before Python 3.14)
96
+ jitterbug analyze rtts.csv.zst --output results.json.zst
92
97
  ```
93
98
 
94
99
  ### Validate input before analyzing
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "jitterbug-inference"
7
- version = "2.2.0"
7
+ version = "2.3.0"
8
8
  description = "Framework for jitter-based network congestion inference"
9
9
  readme = "README.md"
10
10
  keywords = [
@@ -63,6 +63,7 @@ bcp = [
63
63
  bayesian = ["jitterbug-inference[bcp]"]
64
64
  clustering = ["scikit-learn>=1.3"]
65
65
  influx = ["influxdb-client>=1.30.0"]
66
+ zstd = ["zstandard>=0.23; python_version < '3.14'"]
66
67
  visualization = ["matplotlib>=3.5.0"]
67
68
  jupyter = [
68
69
  "ipykernel>=6.0.0",
@@ -73,6 +74,7 @@ all = [
73
74
  "torch>=2.0",
74
75
  "scikit-learn>=1.3",
75
76
  "influxdb-client>=1.30.0",
77
+ "zstandard>=0.23; python_version < '3.14'",
76
78
  "matplotlib>=3.5.0",
77
79
  "ipykernel>=6.0.0",
78
80
  "jupyter>=1.0.0",
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "jitterbug-inference"
7
- version = "2.2.0"
7
+ version = "2.3.0"
8
8
  description = "Framework for jitter-based network congestion inference"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -58,6 +58,8 @@ bayesian = ["jitterbug-inference[bcp]"] # deprecated alias for the old extra na
58
58
  # Non-sequential (clustering) analysis mode: `analysis_mode: clustering`
59
59
  clustering = ["scikit-learn>=1.3"]
60
60
  influx = ["influxdb-client>=1.30.0"]
61
+ # Zstandard (`.zst`) input and output; Python 3.14+ has it in the standard library
62
+ zstd = ["zstandard>=0.23; python_version < '3.14'"]
61
63
  visualization = ["matplotlib>=3.5.0"]
62
64
  jupyter = ["ipykernel>=6.0.0", "jupyter>=1.0.0"]
63
65
  # Every optional back end and front end.
@@ -66,6 +68,7 @@ all = [
66
68
  "torch>=2.0",
67
69
  "scikit-learn>=1.3",
68
70
  "influxdb-client>=1.30.0",
71
+ "zstandard>=0.23; python_version < '3.14'",
69
72
  "matplotlib>=3.5.0",
70
73
  "ipykernel>=6.0.0",
71
74
  "jupyter>=1.0.0",
@@ -15,6 +15,8 @@ from .analysis import (
15
15
  )
16
16
  from .detection import ChangePointDetector
17
17
  from .io import DataLoader
18
+ from .io.compression import open_text
19
+ from .io.exporters import reject_zstd_parquet
18
20
  from .models import (
19
21
  ChangePoint,
20
22
  CongestionInferenceResult,
@@ -312,9 +314,17 @@ class JitterbugAnalyzer:
312
314
  results : CongestionInferenceResult
313
315
  Analysis results to save.
314
316
  output_path : Union[str, Path]
315
- Path to save results to.
317
+ Path to save results to. JSON and CSV are compressed with Zstandard when it
318
+ ends in ``.zst`` (``results.json.zst``).
316
319
  format : Optional[str]
317
320
  Output format ('json', 'csv', 'parquet'). If None, uses config default.
321
+
322
+ Raises
323
+ ------
324
+ ValueError
325
+ If the format is unknown, or Parquet is requested with a ``.zst`` path.
326
+ ImportError
327
+ If the path ends in ``.zst`` and no Zstandard codec is available.
318
328
  """
319
329
  output_path = Path(output_path)
320
330
  format = format or self.config.output_format
@@ -322,14 +332,16 @@ class JitterbugAnalyzer:
322
332
  if format == "json":
323
333
  import json
324
334
 
325
- with output_path.open("w") as f:
335
+ with open_text(output_path, "w") as f:
326
336
  json.dump(results.model_dump(), f, indent=2, default=str)
327
337
 
328
338
  elif format == "csv":
329
339
  df = results.to_dataframe()
330
- df.to_csv(output_path, index=False)
340
+ with open_text(output_path, "w", newline="") as f:
341
+ df.to_csv(f, index=False)
331
342
 
332
343
  elif format == "parquet":
344
+ reject_zstd_parquet(output_path)
333
345
  df = results.to_dataframe()
334
346
  df.to_parquet(output_path)
335
347
 
@@ -0,0 +1,108 @@
1
+ """
2
+ Transparent Zstandard compression for input and output files.
3
+
4
+ A path whose last suffix is ``.zst`` (``rtts.csv.zst``, ``results.json.zst``) is read
5
+ and written through a Zstandard stream; any other path is a plain file. The codec is the
6
+ standard library's ``compression.zstd`` on Python 3.14 and later, otherwise the
7
+ ``zstandard`` package (the ``zstd`` extra).
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import importlib
13
+ import logging
14
+ from pathlib import Path
15
+ from typing import IO, Any, cast
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+ ZSTD_SUFFIX = ".zst"
20
+
21
+ INSTALL_HINT = (
22
+ "Reading or writing .zst files needs Python 3.14+ or the zstandard package. "
23
+ "Install the extra: pip install 'jitterbug-inference[zstd]'"
24
+ )
25
+
26
+
27
+ def is_zstd(path: str | Path) -> bool:
28
+ """
29
+ Return whether ``path`` names a Zstandard-compressed file (last suffix ``.zst``).
30
+
31
+ Parameters
32
+ ----------
33
+ path : str | Path
34
+ File path.
35
+
36
+ Returns
37
+ -------
38
+ bool
39
+ ``True`` for ``*.zst``, case-insensitive.
40
+ """
41
+ return Path(path).suffix.lower() == ZSTD_SUFFIX
42
+
43
+
44
+ def inner_suffix(path: str | Path) -> str:
45
+ """
46
+ Return the suffix that describes the content, ignoring a trailing ``.zst``.
47
+
48
+ Parameters
49
+ ----------
50
+ path : str | Path
51
+ File path.
52
+
53
+ Returns
54
+ -------
55
+ str
56
+ Lower-case suffix, e.g. ``".csv"`` for both ``rtts.csv`` and ``rtts.csv.zst``;
57
+ empty when there is none.
58
+ """
59
+ path = Path(path)
60
+ if is_zstd(path):
61
+ path = path.with_suffix("")
62
+ return path.suffix.lower()
63
+
64
+
65
+ def _zstd_module() -> Any:
66
+ """Return a module with a gzip-style ``open`` for Zstandard, or raise ImportError."""
67
+ for name in ("compression.zstd", "zstandard"):
68
+ try:
69
+ return importlib.import_module(name)
70
+ except ImportError:
71
+ continue
72
+ raise ImportError(INSTALL_HINT)
73
+
74
+
75
+ def open_text(path: str | Path, mode: str = "r", newline: str | None = None) -> IO[str]:
76
+ """
77
+ Open a text file, through a Zstandard stream when ``path`` ends in ``.zst``.
78
+
79
+ Parameters
80
+ ----------
81
+ path : str | Path
82
+ File path.
83
+ mode : str
84
+ ``"r"`` or ``"w"``.
85
+ newline : str | None
86
+ Passed to the text layer, as in :func:`open`. Use ``""`` when handing the stream
87
+ to the ``csv`` module or pandas.
88
+
89
+ Returns
90
+ -------
91
+ IO[str]
92
+ Text stream; use it as a context manager.
93
+
94
+ Raises
95
+ ------
96
+ ValueError
97
+ If ``mode`` is not ``"r"`` or ``"w"``.
98
+ ImportError
99
+ If ``path`` ends in ``.zst`` and no Zstandard codec is available.
100
+ """
101
+ if mode not in ("r", "w"):
102
+ raise ValueError(f"Unsupported mode: {mode!r} (expected 'r' or 'w')")
103
+ path = Path(path)
104
+ if not is_zstd(path):
105
+ return path.open(mode, encoding="utf-8", newline=newline)
106
+ zstd = _zstd_module()
107
+ logger.debug(f"Opening {path} through {zstd.__name__}")
108
+ return cast(IO[str], zstd.open(path, f"{mode}t", encoding="utf-8", newline=newline))
@@ -12,6 +12,7 @@ import numpy as np
12
12
  import pandas as pd
13
13
 
14
14
  from ..models import MAX_RTT_MS, RTTDataset, RTTMeasurement
15
+ from .compression import inner_suffix, open_text
15
16
 
16
17
  logger = logging.getLogger(__name__)
17
18
 
@@ -44,7 +45,8 @@ class DataLoader:
44
45
  Path to the data file.
45
46
  file_format : Optional[str]
46
47
  Format of the file ('csv' or 'json'). If None, it is inferred from the
47
- extension, then from the first line.
48
+ extension, then from the first line. A trailing ``.zst`` means the file is
49
+ Zstandard-compressed (``rtts.csv.zst``) and does not count as the extension.
48
50
 
49
51
  Returns
50
52
  -------
@@ -191,8 +193,9 @@ class DataLoader:
191
193
 
192
194
  def _infer_format(self, file_path: Path) -> str:
193
195
  """
194
- Infer the file format: ``.csv``/``.json``/``.jsonl`` by extension, otherwise
195
- from the first line (a JSON object or a comma-separated header).
196
+ Infer the file format: ``.csv``/``.json``/``.jsonl`` by extension (ignoring a
197
+ trailing ``.zst``), otherwise from the first line (a JSON object or a
198
+ comma-separated header).
196
199
 
197
200
  Parameters
198
201
  ----------
@@ -209,7 +212,7 @@ class DataLoader:
209
212
  ValueError
210
213
  If the file cannot be read as text or its first line matches neither format.
211
214
  """
212
- extension = file_path.suffix.lower()
215
+ extension = inner_suffix(file_path)
213
216
 
214
217
  if extension == ".csv":
215
218
  return "csv"
@@ -217,7 +220,7 @@ class DataLoader:
217
220
  return "json"
218
221
  # Unknown extension: look at the first line
219
222
  try:
220
- with file_path.open() as f:
223
+ with open_text(file_path) as f:
221
224
  first_line = f.readline().strip()
222
225
  except (OSError, UnicodeError) as e:
223
226
  raise ValueError(f"Cannot infer format for file: {file_path}") from e
@@ -245,8 +248,11 @@ class DataLoader:
245
248
  Loaded RTT dataset.
246
249
  """
247
250
  try:
248
- df = pd.read_csv(file_path)
251
+ with open_text(file_path, newline="") as f:
252
+ df = pd.read_csv(f)
249
253
  dataset = self.load_from_dataframe(df)
254
+ except ImportError:
255
+ raise
250
256
  except Exception as e:
251
257
  raise ValueError(f"Failed to load CSV file {file_path}: {e}") from e
252
258
  dataset.metadata.update({"source": "csv", "file_path": str(file_path)})
@@ -270,7 +276,7 @@ class DataLoader:
270
276
  out_of_range = 0
271
277
 
272
278
  try:
273
- with file_path.open() as f:
279
+ with open_text(file_path) as f:
274
280
  for line in f:
275
281
  line = line.strip()
276
282
  if not line:
@@ -311,6 +317,8 @@ class DataLoader:
311
317
  logger.warning(f"Skipping invalid JSON line: {line[:120]!r}")
312
318
  continue
313
319
 
320
+ except ImportError:
321
+ raise
314
322
  except Exception as e:
315
323
  raise ValueError(f"Failed to load JSON file {file_path}: {e}") from e
316
324
 
@@ -1,5 +1,8 @@
1
1
  """
2
2
  Result export utilities.
3
+
4
+ JSON and CSV outputs are Zstandard-compressed when the path ends in ``.zst``
5
+ (``results.json.zst``); see :mod:`jitterbug.io.compression`.
3
6
  """
4
7
 
5
8
  import json
@@ -9,10 +12,19 @@ from pathlib import Path
9
12
  import pandas as pd
10
13
 
11
14
  from ..models import CongestionInferenceResult
15
+ from .compression import is_zstd, open_text
12
16
 
13
17
  logger = logging.getLogger(__name__)
14
18
 
15
19
 
20
+ def reject_zstd_parquet(output_path: Path) -> None:
21
+ """Raise ValueError for ``*.zst`` Parquet output, which would compress twice."""
22
+ if is_zstd(output_path):
23
+ raise ValueError(
24
+ f"Parquet output is already compressed; drop the .zst suffix: {output_path}"
25
+ )
26
+
27
+
16
28
  class ResultExporter:
17
29
  """
18
30
  Exporter for analysis results to various formats.
@@ -32,7 +44,7 @@ class ResultExporter:
32
44
  results : CongestionInferenceResult
33
45
  Analysis results to export.
34
46
  output_path : Union[str, Path]
35
- Path to save JSON file.
47
+ Path to save JSON file; compressed with Zstandard if it ends in ``.zst``.
36
48
  pretty : bool
37
49
  Whether to format JSON with indentation.
38
50
  """
@@ -46,7 +58,7 @@ class ResultExporter:
46
58
  isoformat = getattr(obj, "isoformat", None)
47
59
  return isoformat() if callable(isoformat) else str(obj)
48
60
 
49
- with output_path.open("w") as f:
61
+ with open_text(output_path, "w") as f:
50
62
  if pretty:
51
63
  json.dump(data, f, indent=2, default=json_serializer)
52
64
  else:
@@ -63,7 +75,7 @@ class ResultExporter:
63
75
  results : CongestionInferenceResult
64
76
  Analysis results to export.
65
77
  output_path : Union[str, Path]
66
- Path to save CSV file.
78
+ Path to save CSV file; compressed with Zstandard if it ends in ``.zst``.
67
79
  """
68
80
  output_path = Path(output_path)
69
81
 
@@ -82,7 +94,8 @@ class ResultExporter:
82
94
  for inf in results.inferences
83
95
  ]
84
96
 
85
- df.to_csv(output_path, index=False)
97
+ with open_text(output_path, "w", newline="") as f:
98
+ df.to_csv(f, index=False)
86
99
 
87
100
  logger.info(f"Results exported to CSV: {output_path}")
88
101
 
@@ -98,8 +111,14 @@ class ResultExporter:
98
111
  Analysis results to export.
99
112
  output_path : Union[str, Path]
100
113
  Path to save Parquet file.
114
+
115
+ Raises
116
+ ------
117
+ ValueError
118
+ If ``output_path`` ends in ``.zst``: Parquet compresses its own columns.
101
119
  """
102
120
  output_path = Path(output_path)
121
+ reject_zstd_parquet(output_path)
103
122
 
104
123
  # Convert to DataFrame
105
124
  df = results.to_dataframe()
@@ -129,7 +148,8 @@ class ResultExporter:
129
148
  results : CongestionInferenceResult
130
149
  Analysis results to export.
131
150
  output_path : Union[str, Path]
132
- Path to save summary JSON file.
151
+ Path to save summary JSON file; compressed with Zstandard if it ends in
152
+ ``.zst``.
133
153
  """
134
154
  output_path = Path(output_path)
135
155
 
@@ -162,7 +182,7 @@ class ResultExporter:
162
182
  "max": float(pd.Series(confidences).max()),
163
183
  }
164
184
 
165
- with output_path.open("w") as f:
185
+ with open_text(output_path, "w") as f:
166
186
  json.dump(summary, f, indent=2)
167
187
 
168
188
  logger.info(f"Summary exported to JSON: {output_path}")