sumitENV 0.1.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.
- sumitenv-0.1.0/PKG-INFO +56 -0
- sumitenv-0.1.0/README.md +42 -0
- sumitenv-0.1.0/pyproject.toml +23 -0
- sumitenv-0.1.0/setup.cfg +4 -0
- sumitenv-0.1.0/sumitENV.egg-info/PKG-INFO +56 -0
- sumitenv-0.1.0/sumitENV.egg-info/SOURCES.txt +9 -0
- sumitenv-0.1.0/sumitENV.egg-info/dependency_links.txt +1 -0
- sumitenv-0.1.0/sumitENV.egg-info/top_level.txt +1 -0
- sumitenv-0.1.0/tenv/__init__.py +1 -0
- sumitenv-0.1.0/tenv/run_p4.py +150 -0
- sumitenv-0.1.0/tenv/setup_env.py +75 -0
sumitenv-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sumitENV
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Run sumit403.p4() in an isolated conda environment without crashing your Jupyter kernel
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: pytorch,jupyter,conda,isolated,environment,sumit403
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# Tenv
|
|
16
|
+
|
|
17
|
+
Run `sumit403.p4()` in a completely isolated conda environment — your Jupyter kernel **never crashes**.
|
|
18
|
+
|
|
19
|
+
## The Problem
|
|
20
|
+
|
|
21
|
+
`sumit403.p4()` injects PyTorch code that conflicts with the standard Anaconda environment, causing the kernel to die every time you run it.
|
|
22
|
+
|
|
23
|
+
## The Solution
|
|
24
|
+
|
|
25
|
+
**Tenv** runs `p4()` in a separate subprocess inside a dedicated `p4_env` conda environment. Your main kernel is untouched, figures are captured and displayed inline, and you never need to restart.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install Tenv
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Step 1 — One-time setup
|
|
36
|
+
|
|
37
|
+
Run this **once** to create the isolated environment with PyTorch + sumit403:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from tenv import setup_env
|
|
41
|
+
setup_env()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Step 2 — Run p4 (every time, no crashes)
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from tenv import run_p4
|
|
48
|
+
run_p4()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
That's it. Output streams back to your notebook, matplotlib figures display inline, and your kernel stays alive.
|
|
52
|
+
|
|
53
|
+
## Requirements
|
|
54
|
+
|
|
55
|
+
- Anaconda or Miniconda (conda must be on PATH)
|
|
56
|
+
- Python 3.8+
|
sumitenv-0.1.0/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Tenv
|
|
2
|
+
|
|
3
|
+
Run `sumit403.p4()` in a completely isolated conda environment — your Jupyter kernel **never crashes**.
|
|
4
|
+
|
|
5
|
+
## The Problem
|
|
6
|
+
|
|
7
|
+
`sumit403.p4()` injects PyTorch code that conflicts with the standard Anaconda environment, causing the kernel to die every time you run it.
|
|
8
|
+
|
|
9
|
+
## The Solution
|
|
10
|
+
|
|
11
|
+
**Tenv** runs `p4()` in a separate subprocess inside a dedicated `p4_env` conda environment. Your main kernel is untouched, figures are captured and displayed inline, and you never need to restart.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install Tenv
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Step 1 — One-time setup
|
|
22
|
+
|
|
23
|
+
Run this **once** to create the isolated environment with PyTorch + sumit403:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from tenv import setup_env
|
|
27
|
+
setup_env()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Step 2 — Run p4 (every time, no crashes)
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from tenv import run_p4
|
|
34
|
+
run_p4()
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
That's it. Output streams back to your notebook, matplotlib figures display inline, and your kernel stays alive.
|
|
38
|
+
|
|
39
|
+
## Requirements
|
|
40
|
+
|
|
41
|
+
- Anaconda or Miniconda (conda must be on PATH)
|
|
42
|
+
- Python 3.8+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sumitENV"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Run sumit403.p4() in an isolated conda environment without crashing your Jupyter kernel"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
keywords = ["pytorch", "jupyter", "conda", "isolated", "environment", "sumit403"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.packages.find]
|
|
22
|
+
where = ["."]
|
|
23
|
+
include = ["tenv*"]
|
sumitenv-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sumitENV
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Run sumit403.p4() in an isolated conda environment without crashing your Jupyter kernel
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: pytorch,jupyter,conda,isolated,environment,sumit403
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# Tenv
|
|
16
|
+
|
|
17
|
+
Run `sumit403.p4()` in a completely isolated conda environment — your Jupyter kernel **never crashes**.
|
|
18
|
+
|
|
19
|
+
## The Problem
|
|
20
|
+
|
|
21
|
+
`sumit403.p4()` injects PyTorch code that conflicts with the standard Anaconda environment, causing the kernel to die every time you run it.
|
|
22
|
+
|
|
23
|
+
## The Solution
|
|
24
|
+
|
|
25
|
+
**Tenv** runs `p4()` in a separate subprocess inside a dedicated `p4_env` conda environment. Your main kernel is untouched, figures are captured and displayed inline, and you never need to restart.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install Tenv
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Step 1 — One-time setup
|
|
36
|
+
|
|
37
|
+
Run this **once** to create the isolated environment with PyTorch + sumit403:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from tenv import setup_env
|
|
41
|
+
setup_env()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Step 2 — Run p4 (every time, no crashes)
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from tenv import run_p4
|
|
48
|
+
run_p4()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
That's it. Output streams back to your notebook, matplotlib figures display inline, and your kernel stays alive.
|
|
52
|
+
|
|
53
|
+
## Requirements
|
|
54
|
+
|
|
55
|
+
- Anaconda or Miniconda (conda must be on PATH)
|
|
56
|
+
- Python 3.8+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tenv
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .run_p4 import run_p4, setup_env
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""
|
|
2
|
+
run_p4.py — run sumit403.p4() in an isolated conda environment.
|
|
3
|
+
|
|
4
|
+
Drop this folder next to your Jupyter notebook, then:
|
|
5
|
+
|
|
6
|
+
from tenv import run_p4
|
|
7
|
+
run_p4()
|
|
8
|
+
|
|
9
|
+
The p4 experiment runs in a separate process — your main kernel never crashes.
|
|
10
|
+
Matplotlib figures are saved as PNG files and displayed inline automatically.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
import os
|
|
16
|
+
import tempfile
|
|
17
|
+
import textwrap
|
|
18
|
+
|
|
19
|
+
ENV_NAME = "p4_env"
|
|
20
|
+
|
|
21
|
+
_RUNNER_SCRIPT = textwrap.dedent("""
|
|
22
|
+
import sys
|
|
23
|
+
import os
|
|
24
|
+
|
|
25
|
+
import matplotlib
|
|
26
|
+
matplotlib.use("Agg")
|
|
27
|
+
|
|
28
|
+
import matplotlib.pyplot as _plt_orig
|
|
29
|
+
_fig_counter = [0]
|
|
30
|
+
|
|
31
|
+
_original_show = _plt_orig.show
|
|
32
|
+
def _patched_show(*args, **kwargs):
|
|
33
|
+
_fig_counter[0] += 1
|
|
34
|
+
path = os.path.join(FIGURE_DIR, f"p4_figure_{_fig_counter[0]}.png")
|
|
35
|
+
_plt_orig.savefig(path, bbox_inches="tight", dpi=150)
|
|
36
|
+
_plt_orig.close("all")
|
|
37
|
+
print(f"[FIGURE_SAVED] {path}", flush=True)
|
|
38
|
+
|
|
39
|
+
_plt_orig.show = _patched_show
|
|
40
|
+
|
|
41
|
+
import sumit403
|
|
42
|
+
import io
|
|
43
|
+
from contextlib import redirect_stdout
|
|
44
|
+
|
|
45
|
+
buf = io.StringIO()
|
|
46
|
+
with redirect_stdout(buf):
|
|
47
|
+
sumit403.p4()
|
|
48
|
+
|
|
49
|
+
injected = buf.getvalue()
|
|
50
|
+
|
|
51
|
+
lines = injected.splitlines()
|
|
52
|
+
code_lines = []
|
|
53
|
+
capture = False
|
|
54
|
+
for line in lines:
|
|
55
|
+
if capture:
|
|
56
|
+
code_lines.append(line)
|
|
57
|
+
if line.startswith("[DONE]"):
|
|
58
|
+
capture = True
|
|
59
|
+
|
|
60
|
+
if code_lines:
|
|
61
|
+
exec_code = "\\n".join(code_lines)
|
|
62
|
+
exec(exec_code, {"__name__": "__main__", "FIGURE_DIR": FIGURE_DIR})
|
|
63
|
+
else:
|
|
64
|
+
print(injected, flush=True)
|
|
65
|
+
""")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def setup_env():
|
|
69
|
+
"""
|
|
70
|
+
One-time setup: create the isolated conda environment and install dependencies.
|
|
71
|
+
Run this once before calling run_p4().
|
|
72
|
+
"""
|
|
73
|
+
from tenv.setup_env import setup
|
|
74
|
+
setup()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def run_p4(show_figures=True, figure_dir=None):
|
|
78
|
+
"""
|
|
79
|
+
Run sumit403.p4() in the isolated 'p4_env' conda environment.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
show_figures : bool
|
|
84
|
+
If True (default) and running inside Jupyter, display saved PNG figures inline.
|
|
85
|
+
figure_dir : str or None
|
|
86
|
+
Directory to save figure PNGs. Defaults to a temp directory.
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
list[str]
|
|
91
|
+
Paths to any figures that were saved.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
if figure_dir is None:
|
|
95
|
+
figure_dir = tempfile.mkdtemp(prefix="p4_figures_")
|
|
96
|
+
else:
|
|
97
|
+
os.makedirs(figure_dir, exist_ok=True)
|
|
98
|
+
|
|
99
|
+
script_code = f"FIGURE_DIR = {repr(figure_dir)}\n" + _RUNNER_SCRIPT
|
|
100
|
+
|
|
101
|
+
result = subprocess.run(
|
|
102
|
+
["conda", "run", "--no-capture-output", "-n", ENV_NAME,
|
|
103
|
+
"python", "-c", script_code],
|
|
104
|
+
capture_output=True,
|
|
105
|
+
text=True
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
figure_paths = []
|
|
109
|
+
|
|
110
|
+
if result.stdout:
|
|
111
|
+
for line in result.stdout.splitlines():
|
|
112
|
+
if line.startswith("[FIGURE_SAVED]"):
|
|
113
|
+
fig_path = line.split("[FIGURE_SAVED]", 1)[1].strip()
|
|
114
|
+
figure_paths.append(fig_path)
|
|
115
|
+
else:
|
|
116
|
+
print(line)
|
|
117
|
+
|
|
118
|
+
if result.stderr:
|
|
119
|
+
filtered = [
|
|
120
|
+
ln for ln in result.stderr.splitlines()
|
|
121
|
+
if not ln.strip().startswith("conda") and ln.strip()
|
|
122
|
+
]
|
|
123
|
+
if filtered:
|
|
124
|
+
print("\n[p4 stderr]", file=sys.stderr)
|
|
125
|
+
for ln in filtered:
|
|
126
|
+
print(ln, file=sys.stderr)
|
|
127
|
+
|
|
128
|
+
if result.returncode != 0:
|
|
129
|
+
print(
|
|
130
|
+
f"\n[ERROR] p4 subprocess exited with code {result.returncode}.\n"
|
|
131
|
+
"Make sure you ran setup_env() first:\n"
|
|
132
|
+
" from tenv import setup_env; setup_env()",
|
|
133
|
+
file=sys.stderr
|
|
134
|
+
)
|
|
135
|
+
return figure_paths
|
|
136
|
+
|
|
137
|
+
if show_figures and figure_paths:
|
|
138
|
+
_display_figures(figure_paths)
|
|
139
|
+
|
|
140
|
+
return figure_paths
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _display_figures(paths):
|
|
144
|
+
try:
|
|
145
|
+
from IPython.display import display, Image
|
|
146
|
+
for p in paths:
|
|
147
|
+
if os.path.exists(p):
|
|
148
|
+
display(Image(filename=p))
|
|
149
|
+
except ImportError:
|
|
150
|
+
print(f"[INFO] Figures saved to: {paths}")
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
One-time setup to create the isolated conda environment for sumit403.p4().
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
from tenv import setup_env
|
|
6
|
+
setup_env()
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
ENV_NAME = "p4_env"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def check_conda():
|
|
16
|
+
try:
|
|
17
|
+
subprocess.run(
|
|
18
|
+
["conda", "info", "--json"],
|
|
19
|
+
capture_output=True, text=True, check=True
|
|
20
|
+
)
|
|
21
|
+
return True
|
|
22
|
+
except (FileNotFoundError, subprocess.CalledProcessError):
|
|
23
|
+
return False
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def env_exists():
|
|
27
|
+
result = subprocess.run(
|
|
28
|
+
["conda", "env", "list"],
|
|
29
|
+
capture_output=True, text=True
|
|
30
|
+
)
|
|
31
|
+
return ENV_NAME in result.stdout
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _get_env_python():
|
|
35
|
+
result = subprocess.run(
|
|
36
|
+
["conda", "run", "-n", ENV_NAME, "python", "-c",
|
|
37
|
+
"import sys; print(sys.executable)"],
|
|
38
|
+
capture_output=True, text=True, check=True
|
|
39
|
+
)
|
|
40
|
+
return result.stdout.strip()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def setup():
|
|
44
|
+
if not check_conda():
|
|
45
|
+
print("[ERROR] conda not found. Make sure Anaconda/Miniconda is installed and on PATH.")
|
|
46
|
+
sys.exit(1)
|
|
47
|
+
|
|
48
|
+
if env_exists():
|
|
49
|
+
print(f"[INFO] Environment '{ENV_NAME}' already exists. Skipping creation.")
|
|
50
|
+
else:
|
|
51
|
+
print(f"[INFO] Creating conda environment '{ENV_NAME}' with Python 3.10...")
|
|
52
|
+
subprocess.run(
|
|
53
|
+
["conda", "create", "-n", ENV_NAME, "python=3.10", "-y"],
|
|
54
|
+
check=True
|
|
55
|
+
)
|
|
56
|
+
print("[INFO] Environment created.")
|
|
57
|
+
|
|
58
|
+
python_bin = _get_env_python()
|
|
59
|
+
|
|
60
|
+
print("[INFO] Installing torch (CPU-safe build)...")
|
|
61
|
+
subprocess.run(
|
|
62
|
+
[python_bin, "-m", "pip", "install",
|
|
63
|
+
"torch", "torchvision", "torchaudio",
|
|
64
|
+
"--index-url", "https://download.pytorch.org/whl/cpu"],
|
|
65
|
+
check=True
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
print("[INFO] Installing matplotlib and sumit403==0.6...")
|
|
69
|
+
subprocess.run(
|
|
70
|
+
[python_bin, "-m", "pip", "install", "matplotlib", "sumit403==0.6"],
|
|
71
|
+
check=True
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
print(f"\n[DONE] Environment '{ENV_NAME}' is ready.")
|
|
75
|
+
print("You can now use run_p4() in your notebook without kernel crashes.")
|