eggp 2.2.1__tar.gz → 2.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eggp
3
- Version: 2.2.1
3
+ Version: 2.2.2
4
4
  Summary: Python Wheels for eggp algorithm.
5
5
  Author-email: Fabricio Olivetti <folivetti@users.noreply.github.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -908,6 +908,42 @@ mse = mean_squared_error(y_test, y_pred)
908
908
  print(f"Test MSE: {mse}")
909
909
  ```
910
910
 
911
+ ### Multithreading / RTS options
912
+
913
+ eggp uses GHC's runtime system; the number of Haskell capabilities is
914
+ controlled by the RTS `-N` flag and defaults to **4**. Set `GHCRTS` before the
915
+ first eggp call (ideally before `import eggp`):
916
+
917
+ ```bash
918
+ GHCRTS="-N8" python script.py # 8 capabilities
919
+ GHCRTS="-N" python script.py # all available cores
920
+ ```
921
+
922
+ or in Python, before the first fit:
923
+
924
+ ```python
925
+ import os
926
+ os.environ["GHCRTS"] = "-N8" # or "-N"
927
+ import eggp
928
+ ```
929
+
930
+ For an explicit override of `GHCRTS`, initialize the RTS yourself before the
931
+ first run:
932
+
933
+ ```python
934
+ import eggp
935
+
936
+ with eggp.hs_rts_init(["eggp", "+RTS", "-N8", "-RTS"]):
937
+ model = eggp.EGGP(...)
938
+ model.fit(X, y)
939
+ ```
940
+
941
+ The RTS can only be initialized once per process, so set this before the first
942
+ eggp call. `-N` only controls Haskell capabilities; numerical libraries such as
943
+ OpenBLAS/OpenMP use their own environment variables (`OPENBLAS_NUM_THREADS`,
944
+ `OMP_NUM_THREADS`). The standalone `eggp` executable (built with `-rtsopts`)
945
+ also accepts `eggp +RTS -N8 -RTS ...`.
946
+
911
947
  ## Parameters
912
948
 
913
949
  | Parameter | Type | Default | Description |
@@ -206,6 +206,42 @@ mse = mean_squared_error(y_test, y_pred)
206
206
  print(f"Test MSE: {mse}")
207
207
  ```
208
208
 
209
+ ### Multithreading / RTS options
210
+
211
+ eggp uses GHC's runtime system; the number of Haskell capabilities is
212
+ controlled by the RTS `-N` flag and defaults to **4**. Set `GHCRTS` before the
213
+ first eggp call (ideally before `import eggp`):
214
+
215
+ ```bash
216
+ GHCRTS="-N8" python script.py # 8 capabilities
217
+ GHCRTS="-N" python script.py # all available cores
218
+ ```
219
+
220
+ or in Python, before the first fit:
221
+
222
+ ```python
223
+ import os
224
+ os.environ["GHCRTS"] = "-N8" # or "-N"
225
+ import eggp
226
+ ```
227
+
228
+ For an explicit override of `GHCRTS`, initialize the RTS yourself before the
229
+ first run:
230
+
231
+ ```python
232
+ import eggp
233
+
234
+ with eggp.hs_rts_init(["eggp", "+RTS", "-N8", "-RTS"]):
235
+ model = eggp.EGGP(...)
236
+ model.fit(X, y)
237
+ ```
238
+
239
+ The RTS can only be initialized once per process, so set this before the first
240
+ eggp call. `-N` only controls Haskell capabilities; numerical libraries such as
241
+ OpenBLAS/OpenMP use their own environment variables (`OPENBLAS_NUM_THREADS`,
242
+ `OMP_NUM_THREADS`). The standalone `eggp` executable (built with `-rtsopts`)
243
+ also accepts `eggp +RTS -N8 -RTS ...`.
244
+
209
245
  ## Parameters
210
246
 
211
247
  | Parameter | Type | Default | Description |
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "eggp"
15
- version = "2.2.1"
15
+ version = "2.2.2"
16
16
  authors = [{ name = "Fabricio Olivetti", email = "folivetti@users.noreply.github.com" }]
17
17
  description = "Python Wheels for eggp algorithm."
18
18
  readme = "README.md"
@@ -1,7 +1,7 @@
1
1
  import atexit
2
2
  from contextlib import contextmanager
3
3
  from threading import Lock
4
- from typing import Iterator, List
4
+ from typing import Iterator, List, Optional
5
5
  import string
6
6
  from io import StringIO
7
7
  import os
@@ -15,12 +15,17 @@ from sklearn.utils.validation import check_X_y, check_array, check_is_fitted
15
15
  from sklearn.metrics import mean_squared_error, r2_score
16
16
  import matplotlib.pyplot as plt
17
17
 
18
- # GHC auto-initializes the RTS when the shared library is loaded (during the
19
- # _binding import below). At that point it reads the GHCRTS env var for flags;
20
- # if unset, defaults to -N1. Set it here so the RTS starts with the right
21
- # number of capabilities.
22
- if os.environ.get("GHCRTS") is None:
23
- os.environ["GHCRTS"] = "-N4"
18
+ # GHC reads the GHCRTS env var when the RTS is initialized (at the first
19
+ # hs_init call, during the first eggp call). Set GHCRTS before the first eggp
20
+ # call (ideally before this import) to customize the runtime, e.g.
21
+ # GHCRTS="-N8" for 8 capabilities or GHCRTS="-N" for all cores. Keep the
22
+ # historical default of 4 capabilities when the user did not specify -N
23
+ # themselves; other GHCRTS flags (e.g. GC tuning) are preserved.
24
+ _ghcrts = os.environ.get("GHCRTS", "")
25
+ _has_n = any(tok == "-N" or (tok.startswith("-N") and tok[2:].isdigit())
26
+ for tok in _ghcrts.split())
27
+ if not _has_n:
28
+ os.environ["GHCRTS"] = (_ghcrts + " -N4").strip()
24
29
 
25
30
  from ._binding import (
26
31
  unsafe_hs_eggp_version,
@@ -50,7 +55,7 @@ def _get_hs_eggp_run_data():
50
55
  _hs_eggp_run_data = lib.hs_eggp_run_data
51
56
  return _hs_eggp_run_data
52
57
 
53
- VERSION: str = "2.2.1"
58
+ VERSION: str = "2.2.2"
54
59
 
55
60
 
56
61
  _hs_rts_init: bool = False
@@ -63,13 +68,24 @@ def hs_rts_exit() -> None:
63
68
 
64
69
 
65
70
  @contextmanager
66
- def hs_rts_init(args: List[str] = ["eggp", "+RTS", "-N4", "-RTS"]) -> Iterator[None]:
71
+ def hs_rts_init(args: Optional[List[str]] = None) -> Iterator[None]:
72
+ ''' Initialize the GHC RTS once (the first eggp call does this implicitly).
73
+
74
+ With no ``args`` the RTS reads ``GHCRTS``: e.g. ``GHCRTS="-N8"`` for 8
75
+ capabilities or ``GHCRTS="-N"`` for all cores. The package defaults to
76
+ ``-N4`` when no ``-N`` is present in ``GHCRTS``. Passing explicit
77
+ arguments such as ``["eggp", "+RTS", "-N8", "-RTS"]`` overrides
78
+ ``GHCRTS``.
79
+
80
+ The RTS can only be initialized once per process, so set ``GHCRTS`` or
81
+ call this before the first eggp run.
82
+ '''
67
83
  global _hs_rts_init
68
84
  global _hs_rts_lock
69
85
  with _hs_rts_lock:
70
86
  if not _hs_rts_init:
71
87
  _hs_rts_init = True
72
- unsafe_hs_eggp_init(args)
88
+ unsafe_hs_eggp_init(["eggp"] if args is None else args)
73
89
  atexit.register(hs_rts_exit)
74
90
  yield None
75
91
 
@@ -81,11 +97,10 @@ def version() -> str:
81
97
 
82
98
  def main(args: List[str] = []) -> int:
83
99
  # args often come from sys.argv which includes the program name at [0].
84
- # Strip it and prepend RTS flags so hs_init sees +RTS -N{numCores} -RTS.
100
+ # Strip it; GHCRTS (or an explicit +RTS section in the CLI args) controls
101
+ # the RTS, so do not inject -N here.
85
102
  cli_args = args[1:] if args and not args[0].startswith('-') else args
86
- rts_flags = ["+RTS", "-N4", "-RTS"]
87
- rts_args = ["eggp"] + rts_flags
88
- with hs_rts_init(rts_args + cli_args):
103
+ with hs_rts_init(["eggp"] + cli_args):
89
104
  return unsafe_hs_eggp_main()
90
105
 
91
106
  def eggp_run(dataset: str, gen: int, nPop: int, maxSize: int, nTournament: int, pc: float, pm: float, nonterminals: str, loss: str, optIter: int, optRepeat: int, nParams: int, split: int, max_time : int, simplify: int, trace : int, generational : int, dumpTo: str, loadFrom: str, varnames : str, useFracBayes: int, dbFile: str = "", dbFitFile: str = "", dbDataset: str = "", dbCacheSize: int = 100000, dbFlushEvery: int = 0) -> str:
@@ -2,6 +2,10 @@
2
2
  %{
3
3
  #include "EGGP_stub.h"
4
4
 
5
+ /* RTS options are accepted only through hs_init_with_rtsopts for a shared
6
+ library; declare it explicitly (RtsAPI.h) since the stub header may not. */
7
+ extern void hs_init_with_rtsopts(int *argc, char **argv[]);
8
+
5
9
  char * unsafe_hs_eggp_version() {
6
10
  return hs_eggp_version();
7
11
  }
@@ -15,7 +19,7 @@ char * unsafe_hs_eggp_run( char *dataset, int gens, int nPop, int maxSize, int n
15
19
  }
16
20
 
17
21
  void unsafe_hs_eggp_init(int argc, char **argv) {
18
- hs_init(&argc, &argv);
22
+ hs_init_with_rtsopts(&argc, &argv);
19
23
  }
20
24
 
21
25
  void unsafe_hs_eggp_exit() {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eggp
3
- Version: 2.2.1
3
+ Version: 2.2.2
4
4
  Summary: Python Wheels for eggp algorithm.
5
5
  Author-email: Fabricio Olivetti <folivetti@users.noreply.github.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -908,6 +908,42 @@ mse = mean_squared_error(y_test, y_pred)
908
908
  print(f"Test MSE: {mse}")
909
909
  ```
910
910
 
911
+ ### Multithreading / RTS options
912
+
913
+ eggp uses GHC's runtime system; the number of Haskell capabilities is
914
+ controlled by the RTS `-N` flag and defaults to **4**. Set `GHCRTS` before the
915
+ first eggp call (ideally before `import eggp`):
916
+
917
+ ```bash
918
+ GHCRTS="-N8" python script.py # 8 capabilities
919
+ GHCRTS="-N" python script.py # all available cores
920
+ ```
921
+
922
+ or in Python, before the first fit:
923
+
924
+ ```python
925
+ import os
926
+ os.environ["GHCRTS"] = "-N8" # or "-N"
927
+ import eggp
928
+ ```
929
+
930
+ For an explicit override of `GHCRTS`, initialize the RTS yourself before the
931
+ first run:
932
+
933
+ ```python
934
+ import eggp
935
+
936
+ with eggp.hs_rts_init(["eggp", "+RTS", "-N8", "-RTS"]):
937
+ model = eggp.EGGP(...)
938
+ model.fit(X, y)
939
+ ```
940
+
941
+ The RTS can only be initialized once per process, so set this before the first
942
+ eggp call. `-N` only controls Haskell capabilities; numerical libraries such as
943
+ OpenBLAS/OpenMP use their own environment variables (`OPENBLAS_NUM_THREADS`,
944
+ `OMP_NUM_THREADS`). The standalone `eggp` executable (built with `-rtsopts`)
945
+ also accepts `eggp +RTS -N8 -RTS ...`.
946
+
911
947
  ## Parameters
912
948
 
913
949
  | Parameter | Type | Default | Description |
@@ -6,7 +6,6 @@ src/eggp/__init__.py
6
6
  src/eggp/__main__.py
7
7
  src/eggp/_binding.pyi
8
8
  src/eggp/binding.i
9
- src/eggp/binding.py
10
9
  src/eggp/typing.py
11
10
  src/eggp.egg-info/PKG-INFO
12
11
  src/eggp.egg-info/SOURCES.txt
@@ -1,66 +0,0 @@
1
- # This file was automatically generated by SWIG (https://www.swig.org).
2
- # Version 4.5.0
3
- #
4
- # Do not make changes to this file unless you know what you are doing - modify
5
- # the SWIG interface file instead.
6
-
7
- import typing
8
- # Import the low-level C/C++ module
9
- if getattr(globals().get("__spec__"), "parent", None) or __package__ or "." in __name__:
10
- from . import _binding
11
- else:
12
- import _binding
13
-
14
- import builtins as __builtin__
15
-
16
- def _swig_repr(self):
17
- try:
18
- strthis = "proxy of " + self.this.__repr__()
19
- except __builtin__.Exception:
20
- strthis = ""
21
- return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
22
-
23
-
24
- def _swig_setattr_nondynamic_instance_variable(set):
25
- def set_instance_attr(self, name, value):
26
- if name == "this":
27
- set(self, name, value)
28
- elif name == "thisown":
29
- self.this.own(value)
30
- elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
31
- set(self, name, value)
32
- else:
33
- raise AttributeError("You cannot add instance attributes to %s" % self)
34
- return set_instance_attr
35
-
36
-
37
- def _swig_setattr_nondynamic_class_variable(set):
38
- def set_class_attr(cls, name, value):
39
- if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
40
- set(cls, name, value)
41
- else:
42
- raise AttributeError("You cannot add class attributes to %s" % cls)
43
- return set_class_attr
44
-
45
-
46
- class _SwigNonDynamicMeta(type):
47
- """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
48
- __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
49
-
50
-
51
-
52
- def unsafe_hs_eggp_version():
53
- return _binding.unsafe_hs_eggp_version()
54
-
55
- def unsafe_hs_eggp_main():
56
- return _binding.unsafe_hs_eggp_main()
57
-
58
- def unsafe_hs_eggp_run(dataset, gens, nPop, maxSize, nTournament, p, pm, nonterminals, loss, optIter, optRepeat, nParams, split, max_time, simplify, trace, generational, dumpTo, loadFrom, varnames, useFracBayes, dbFile, dbFitFile, dbDataset, dbCacheSize, dbFlushEvery):
59
- return _binding.unsafe_hs_eggp_run(dataset, gens, nPop, maxSize, nTournament, p, pm, nonterminals, loss, optIter, optRepeat, nParams, split, max_time, simplify, trace, generational, dumpTo, loadFrom, varnames, useFracBayes, dbFile, dbFitFile, dbDataset, dbCacheSize, dbFlushEvery)
60
-
61
- def unsafe_hs_eggp_init(argc):
62
- return _binding.unsafe_hs_eggp_init(argc)
63
-
64
- def unsafe_hs_eggp_exit():
65
- return _binding.unsafe_hs_eggp_exit()
66
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes