direct-evolution-together 0.0.1__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.
- direct_evolution_together-0.0.1/.gitignore +233 -0
- direct_evolution_together-0.0.1/LICENSE +21 -0
- direct_evolution_together-0.0.1/PKG-INFO +57 -0
- direct_evolution_together-0.0.1/README.md +9 -0
- direct_evolution_together-0.0.1/direct_evolution_together/__init__.py +1 -0
- direct_evolution_together-0.0.1/direct_evolution_together/admin.py +11 -0
- direct_evolution_together-0.0.1/direct_evolution_together/apps.py +39 -0
- direct_evolution_together-0.0.1/direct_evolution_together/asgi.py +9 -0
- direct_evolution_together-0.0.1/direct_evolution_together/cli.py +200 -0
- direct_evolution_together-0.0.1/direct_evolution_together/config.nims +4 -0
- direct_evolution_together-0.0.1/direct_evolution_together/cppn.py +431 -0
- direct_evolution_together-0.0.1/direct_evolution_together/direct_evolution_together.nimble +10 -0
- direct_evolution_together-0.0.1/direct_evolution_together/migrations/0001_initial.py +27 -0
- direct_evolution_together-0.0.1/direct_evolution_together/migrations/__init__.py +0 -0
- direct_evolution_together-0.0.1/direct_evolution_together/models.py +25 -0
- direct_evolution_together-0.0.1/direct_evolution_together/mummy_ws.nim +1360 -0
- direct_evolution_together-0.0.1/direct_evolution_together/settings.py +134 -0
- direct_evolution_together-0.0.1/direct_evolution_together/templates/direct_evolution_together/admin_reset.html +162 -0
- direct_evolution_together-0.0.1/direct_evolution_together/templates/direct_evolution_together/index.html +3145 -0
- direct_evolution_together-0.0.1/direct_evolution_together/urls.py +16 -0
- direct_evolution_together-0.0.1/direct_evolution_together/views.py +305 -0
- direct_evolution_together-0.0.1/direct_evolution_together/ws_bridge.py +201 -0
- direct_evolution_together-0.0.1/direct_evolution_together/ws_server.py +46 -0
- direct_evolution_together-0.0.1/pyproject.toml +113 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
uv.lock
|
|
100
|
+
|
|
101
|
+
# poetry
|
|
102
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
103
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
104
|
+
# commonly ignored for libraries.
|
|
105
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
106
|
+
# poetry.lock
|
|
107
|
+
# poetry.toml
|
|
108
|
+
|
|
109
|
+
# pdm
|
|
110
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
111
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
112
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
113
|
+
# pdm.lock
|
|
114
|
+
# pdm.toml
|
|
115
|
+
.pdm-python
|
|
116
|
+
.pdm-build/
|
|
117
|
+
|
|
118
|
+
# pixi
|
|
119
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
120
|
+
# pixi.lock
|
|
121
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
122
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
123
|
+
.pixi/*
|
|
124
|
+
!.pixi/config.toml
|
|
125
|
+
|
|
126
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
127
|
+
__pypackages__/
|
|
128
|
+
|
|
129
|
+
# Celery stuff
|
|
130
|
+
celerybeat-schedule*
|
|
131
|
+
celerybeat.pid
|
|
132
|
+
|
|
133
|
+
# Redis
|
|
134
|
+
*.rdb
|
|
135
|
+
*.aof
|
|
136
|
+
*.pid
|
|
137
|
+
|
|
138
|
+
# RabbitMQ
|
|
139
|
+
mnesia/
|
|
140
|
+
rabbitmq/
|
|
141
|
+
rabbitmq-data/
|
|
142
|
+
|
|
143
|
+
# ActiveMQ
|
|
144
|
+
activemq-data/
|
|
145
|
+
|
|
146
|
+
# SageMath parsed files
|
|
147
|
+
*.sage.py
|
|
148
|
+
|
|
149
|
+
# Environments
|
|
150
|
+
.env
|
|
151
|
+
.env.*
|
|
152
|
+
!.env.sample
|
|
153
|
+
.envrc
|
|
154
|
+
.venv
|
|
155
|
+
env/
|
|
156
|
+
venv/
|
|
157
|
+
ENV/
|
|
158
|
+
env.bak/
|
|
159
|
+
venv.bak/
|
|
160
|
+
|
|
161
|
+
# Deploy / local generated files
|
|
162
|
+
justfile
|
|
163
|
+
uv_publish.sh
|
|
164
|
+
.pypi
|
|
165
|
+
deploy/*.rendered*
|
|
166
|
+
deploy/*.local*
|
|
167
|
+
*.secret*
|
|
168
|
+
*.bak
|
|
169
|
+
db.sqlite3-*
|
|
170
|
+
nimcache/
|
|
171
|
+
direct_evolution_together/nimble.paths
|
|
172
|
+
direct_evolution_together/nimble.develop
|
|
173
|
+
direct_evolution_together/nimbledeps
|
|
174
|
+
|
|
175
|
+
# Spyder project settings
|
|
176
|
+
.spyderproject
|
|
177
|
+
.spyproject
|
|
178
|
+
|
|
179
|
+
# Rope project settings
|
|
180
|
+
.ropeproject
|
|
181
|
+
|
|
182
|
+
# mkdocs/Zensical documentation
|
|
183
|
+
/site
|
|
184
|
+
|
|
185
|
+
# mypy
|
|
186
|
+
.mypy_cache/
|
|
187
|
+
.dmypy.json
|
|
188
|
+
dmypy.json
|
|
189
|
+
|
|
190
|
+
# Pyre type checker
|
|
191
|
+
.pyre/
|
|
192
|
+
|
|
193
|
+
# pytype static type analyzer
|
|
194
|
+
.pytype/
|
|
195
|
+
|
|
196
|
+
# Cython debug symbols
|
|
197
|
+
cython_debug/
|
|
198
|
+
|
|
199
|
+
# PyCharm
|
|
200
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
201
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
203
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
204
|
+
# .idea/
|
|
205
|
+
|
|
206
|
+
# Abstra
|
|
207
|
+
# Abstra is an AI-powered process automation framework.
|
|
208
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
209
|
+
# Learn more at https://abstra.io/docs
|
|
210
|
+
.abstra/
|
|
211
|
+
|
|
212
|
+
# Visual Studio Code
|
|
213
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
214
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
215
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
216
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
217
|
+
# .vscode/
|
|
218
|
+
# Temporary file for partial code execution
|
|
219
|
+
tempCodeRunnerFile.py
|
|
220
|
+
|
|
221
|
+
# Ruff stuff:
|
|
222
|
+
.ruff_cache/
|
|
223
|
+
|
|
224
|
+
# PyPI configuration file
|
|
225
|
+
.pypirc
|
|
226
|
+
|
|
227
|
+
# Marimo
|
|
228
|
+
marimo/_static/
|
|
229
|
+
marimo/_lsp/
|
|
230
|
+
__marimo__/
|
|
231
|
+
|
|
232
|
+
# Streamlit
|
|
233
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Phil Wang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: direct-evolution-together
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: directed evolution on neural networks, together
|
|
5
|
+
Project-URL: Homepage, https://pypi.org/project/direct-evolution-together/
|
|
6
|
+
Project-URL: Repository, https://github.com/lucidrains/direct-evolution-together
|
|
7
|
+
Author-email: Phil Wang <lucidrains@gmail.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 Phil Wang
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: artificial intelligence,deep learning,directed evolution,genetic algorithms
|
|
31
|
+
Classifier: Development Status :: 4 - Beta
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
36
|
+
Requires-Python: >=3.10
|
|
37
|
+
Requires-Dist: django>=5.1
|
|
38
|
+
Requires-Dist: nimporter-plus>=0.0.10
|
|
39
|
+
Requires-Dist: numpy>=2.2.6
|
|
40
|
+
Requires-Dist: packaging>=26.3
|
|
41
|
+
Requires-Dist: torch-einops-utils>=0.2.6
|
|
42
|
+
Requires-Dist: torch>=2.5
|
|
43
|
+
Requires-Dist: uvicorn>=0.34
|
|
44
|
+
Provides-Extra: examples
|
|
45
|
+
Provides-Extra: test
|
|
46
|
+
Requires-Dist: pytest; extra == 'test'
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+
# direct-evolution-together
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install direct-evolution-together
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
direct-evolution-together
|
|
57
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import nimporter_plus # noqa: F401 - registers Nim import hook
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from django.contrib import admin
|
|
2
|
+
|
|
3
|
+
from direct_evolution_together.models import ChatMessage
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@admin.register(ChatMessage)
|
|
7
|
+
class ChatMessageAdmin(admin.ModelAdmin):
|
|
8
|
+
list_display = ("room", "username", "message", "created_at")
|
|
9
|
+
list_filter = ("room",)
|
|
10
|
+
search_fields = ("username", "message")
|
|
11
|
+
ordering = ("-created_at", "-id")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from django.apps import AppConfig
|
|
5
|
+
from django.conf import settings
|
|
6
|
+
from django.db.backends.signals import connection_created
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _enable_sqlite_wal(sender, connection, **kwargs) -> None:
|
|
10
|
+
if connection.vendor == "sqlite":
|
|
11
|
+
with connection.cursor() as cursor:
|
|
12
|
+
cursor.execute("PRAGMA journal_mode=WAL;")
|
|
13
|
+
cursor.execute("PRAGMA synchronous=NORMAL;")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DirectEvolutionTogetherConfig(AppConfig):
|
|
17
|
+
default_auto_field = "django.db.models.BigAutoField"
|
|
18
|
+
name = "direct_evolution_together"
|
|
19
|
+
|
|
20
|
+
def ready(self) -> None:
|
|
21
|
+
connection_created.connect(_enable_sqlite_wal, dispatch_uid="det_sqlite_wal")
|
|
22
|
+
is_runserver = "runserver" in sys.argv or os.environ.get("DET_START_WS") == "1"
|
|
23
|
+
if not is_runserver:
|
|
24
|
+
return
|
|
25
|
+
# Under StatReloader, only start Mummy in the serving child process (RUN_MAIN=true),
|
|
26
|
+
# or immediately when --noreload is used.
|
|
27
|
+
if os.environ.get("RUN_MAIN") == "true" or "--noreload" in sys.argv:
|
|
28
|
+
from direct_evolution_together.ws_bridge import start_ws_server
|
|
29
|
+
|
|
30
|
+
start_ws_server(
|
|
31
|
+
host=settings.WS_HOST,
|
|
32
|
+
port=settings.WS_PORT,
|
|
33
|
+
pop_size=settings.POPULATION_SIZE,
|
|
34
|
+
min_votes=settings.MIN_VOTES,
|
|
35
|
+
max_votes=settings.MAX_VOTES_PER_USER,
|
|
36
|
+
mut_sigma=settings.MUTATION_SIGMA,
|
|
37
|
+
elite_frac=settings.ELITE_FRAC,
|
|
38
|
+
crossover_rate=settings.CROSSOVER_RATE,
|
|
39
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""ASGI entrypoint for running Django HTTP views under Uvicorn."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from django.core.asgi import get_asgi_application
|
|
6
|
+
|
|
7
|
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "direct_evolution_together.settings")
|
|
8
|
+
|
|
9
|
+
application = get_asgi_application()
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import shutil
|
|
4
|
+
import socket
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import threading
|
|
8
|
+
import time
|
|
9
|
+
import webbrowser
|
|
10
|
+
|
|
11
|
+
NIM_INSTALL_GUIDE = """\
|
|
12
|
+
direct-evolution-together runs its WebSocket server on Nim + Mummy
|
|
13
|
+
(we intentionally ship pure Nim source with no precompiled binaries!).
|
|
14
|
+
|
|
15
|
+
To install Nim & Nimble packages:
|
|
16
|
+
1. Install Nim:
|
|
17
|
+
- macOS: brew install nim
|
|
18
|
+
- Linux / Unix: curl https://nim-lang.org/choosenim/init.sh -sSf | sh
|
|
19
|
+
- Any platform: https://nim-lang.org/install.html
|
|
20
|
+
2. Install required Nim packages:
|
|
21
|
+
nimble install -y mummy nimpy
|
|
22
|
+
3. Re-run:
|
|
23
|
+
direct-evolution-together
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def check_nim_toolchain(*, auto_install_deps: bool = False) -> tuple[bool, str]:
|
|
28
|
+
"""Verify Nim, Nimble, mummy, and nimpy are available for compiling Mummy."""
|
|
29
|
+
if shutil.which("nim") is None or shutil.which("nimble") is None:
|
|
30
|
+
return False, "Missing `nim` or `nimble` in PATH.\n\n" + NIM_INSTALL_GUIDE
|
|
31
|
+
|
|
32
|
+
missing = []
|
|
33
|
+
for pkg in ("mummy", "nimpy"):
|
|
34
|
+
res = subprocess.run(
|
|
35
|
+
["nimble", "path", pkg],
|
|
36
|
+
capture_output=True,
|
|
37
|
+
text=True,
|
|
38
|
+
check=False,
|
|
39
|
+
)
|
|
40
|
+
if res.returncode != 0:
|
|
41
|
+
missing.append(pkg)
|
|
42
|
+
|
|
43
|
+
if missing and auto_install_deps:
|
|
44
|
+
install_res = subprocess.run(
|
|
45
|
+
["nimble", "install", "-y", *missing],
|
|
46
|
+
check=False,
|
|
47
|
+
)
|
|
48
|
+
if install_res.returncode == 0:
|
|
49
|
+
missing = []
|
|
50
|
+
|
|
51
|
+
if missing:
|
|
52
|
+
pkg_list = " ".join(missing)
|
|
53
|
+
return (
|
|
54
|
+
False,
|
|
55
|
+
f"Nim is installed, but required Nimble package(s) are missing: {pkg_list}\n"
|
|
56
|
+
f"Run `nimble install -y {pkg_list}` (or pass `--install-nim-deps`) and try again.\n\n"
|
|
57
|
+
+ NIM_INSTALL_GUIDE,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
return True, "Nim toolchain OK (nim, nimble, mummy, nimpy)."
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def open_browser_when_ready(host: str, port: int, timeout: float = 10.0) -> threading.Thread:
|
|
64
|
+
"""Open the local Web UI URL in the default browser once the HTTP port is accepting connections."""
|
|
65
|
+
browse_host = "127.0.0.1" if host in ("0.0.0.0", "::", "") else host
|
|
66
|
+
url = f"http://{browse_host}:{port}/"
|
|
67
|
+
|
|
68
|
+
def _worker() -> None:
|
|
69
|
+
deadline = time.monotonic() + timeout
|
|
70
|
+
while time.monotonic() < deadline:
|
|
71
|
+
try:
|
|
72
|
+
with socket.create_connection((browse_host, port), timeout=0.25):
|
|
73
|
+
webbrowser.open(url, new=2)
|
|
74
|
+
return
|
|
75
|
+
except OSError:
|
|
76
|
+
time.sleep(0.1)
|
|
77
|
+
|
|
78
|
+
thread = threading.Thread(target=_worker, name="det-browser-open", daemon=True)
|
|
79
|
+
thread.start()
|
|
80
|
+
return thread
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def main() -> None:
|
|
84
|
+
"""Run auto-migrations, verify Nim toolchain, and launch Django + Mummy."""
|
|
85
|
+
from direct_evolution_together.settings import load_dotenv
|
|
86
|
+
|
|
87
|
+
load_dotenv()
|
|
88
|
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "direct_evolution_together.settings")
|
|
89
|
+
|
|
90
|
+
parser = argparse.ArgumentParser(
|
|
91
|
+
prog="direct-evolution-together",
|
|
92
|
+
description="Launch direct-evolution-together (Django web UI + Nim Mummy WebSockets + PyTorch CPPN)",
|
|
93
|
+
)
|
|
94
|
+
parser.add_argument("--host", default=os.getenv("HOST", "127.0.0.1"))
|
|
95
|
+
parser.add_argument("--port", type=int, default=int(os.getenv("PORT", "8000")))
|
|
96
|
+
parser.add_argument("--ws-host", default=os.getenv("MUMMY_WS_HOST", "127.0.0.1"))
|
|
97
|
+
parser.add_argument("--ws-port", type=int, default=int(os.getenv("MUMMY_WS_PORT", "8001")))
|
|
98
|
+
parser.add_argument(
|
|
99
|
+
"--population-size",
|
|
100
|
+
type=int,
|
|
101
|
+
default=int(os.getenv("MUMMY_POP_SIZE", "30")),
|
|
102
|
+
help="Fixed population size for public rooms and default for private rooms (3-64, default: 30)",
|
|
103
|
+
)
|
|
104
|
+
parser.add_argument(
|
|
105
|
+
"--max-votes-per-user",
|
|
106
|
+
type=int,
|
|
107
|
+
default=int(os.getenv("MUMMY_MAX_VOTES", "5")),
|
|
108
|
+
help="Max active votes per user per round in public rooms and default for private rooms (1-20, default: 5)",
|
|
109
|
+
)
|
|
110
|
+
parser.add_argument(
|
|
111
|
+
"--mutation-sigma",
|
|
112
|
+
type=float,
|
|
113
|
+
default=float(os.getenv("MUMMY_MUT_SIGMA", "0.35")),
|
|
114
|
+
help="Constant GA mutation sigma for public rooms and default for private rooms (0.05-1.0, default: 0.35)",
|
|
115
|
+
)
|
|
116
|
+
parser.add_argument(
|
|
117
|
+
"--elite-frac",
|
|
118
|
+
type=float,
|
|
119
|
+
default=float(os.getenv("MUMMY_ELITE_FRAC", "0.10")),
|
|
120
|
+
help="Elite fraction carried over per generation for public rooms and default for private rooms (0.0-0.5, default: 0.10)",
|
|
121
|
+
)
|
|
122
|
+
parser.add_argument(
|
|
123
|
+
"--crossover-rate",
|
|
124
|
+
type=float,
|
|
125
|
+
default=float(os.getenv("MUMMY_CROSSOVER_RATE", "0.75")),
|
|
126
|
+
help="Crossover probability for breeding for public rooms and default for private rooms (0.0-1.0, default: 0.75)",
|
|
127
|
+
)
|
|
128
|
+
parser.add_argument("--reload", action="store_true", help="Enable Django dev autoreloader")
|
|
129
|
+
parser.add_argument("--noreload", action="store_true", help="Disable Django autoreloader (default)")
|
|
130
|
+
parser.add_argument("--no-browser", action="store_true", help="Do not automatically open the Web UI in a browser")
|
|
131
|
+
parser.add_argument("--check", action="store_true", help="Check Nim/Mummy readiness and exit")
|
|
132
|
+
parser.add_argument(
|
|
133
|
+
"--install-nim-deps",
|
|
134
|
+
action="store_true",
|
|
135
|
+
help="Automatically run `nimble install -y mummy nimpy` if missing",
|
|
136
|
+
)
|
|
137
|
+
args = parser.parse_args()
|
|
138
|
+
|
|
139
|
+
is_reloader_child = os.environ.get("RUN_MAIN") == "true"
|
|
140
|
+
if not is_reloader_child:
|
|
141
|
+
ok, message = check_nim_toolchain(auto_install_deps=args.install_nim_deps)
|
|
142
|
+
if not ok:
|
|
143
|
+
print(message, file=sys.stderr)
|
|
144
|
+
raise SystemExit(1)
|
|
145
|
+
if args.check:
|
|
146
|
+
print(message)
|
|
147
|
+
return
|
|
148
|
+
|
|
149
|
+
pop_size = max(3, min(64, args.population_size))
|
|
150
|
+
max_votes = max(1, min(20, args.max_votes_per_user))
|
|
151
|
+
mut_sigma = max(0.05, min(1.0, float(args.mutation_sigma)))
|
|
152
|
+
elite_frac = max(0.0, min(0.5, float(args.elite_frac)))
|
|
153
|
+
crossover_rate = max(0.0, min(1.0, float(args.crossover_rate)))
|
|
154
|
+
os.environ["MUMMY_WS_HOST"] = args.ws_host
|
|
155
|
+
os.environ["MUMMY_WS_PORT"] = str(args.ws_port)
|
|
156
|
+
os.environ["MUMMY_POP_SIZE"] = str(pop_size)
|
|
157
|
+
os.environ["MUMMY_MAX_VOTES"] = str(max_votes)
|
|
158
|
+
os.environ["MUMMY_MUT_SIGMA"] = f"{mut_sigma:.2f}"
|
|
159
|
+
os.environ["MUMMY_ELITE_FRAC"] = f"{elite_frac:.2f}"
|
|
160
|
+
os.environ["MUMMY_CROSSOVER_RATE"] = f"{crossover_rate:.2f}"
|
|
161
|
+
|
|
162
|
+
import django
|
|
163
|
+
from django.core.management import call_command, execute_from_command_line
|
|
164
|
+
|
|
165
|
+
use_noreload = (not args.reload) or args.noreload
|
|
166
|
+
|
|
167
|
+
if not is_reloader_child:
|
|
168
|
+
os.environ["DET_START_WS"] = "0"
|
|
169
|
+
django.setup()
|
|
170
|
+
call_command("migrate", interactive=False, verbosity=0)
|
|
171
|
+
print(
|
|
172
|
+
f"direct-evolution-together · Web UI: http://{args.host}:{args.port}/ "
|
|
173
|
+
f"| WebSocket (Nim + Mummy): ws://{args.ws_host}:{args.ws_port}",
|
|
174
|
+
flush=True,
|
|
175
|
+
)
|
|
176
|
+
if use_noreload:
|
|
177
|
+
from direct_evolution_together.ws_bridge import start_ws_server
|
|
178
|
+
|
|
179
|
+
start_ws_server(
|
|
180
|
+
host=args.ws_host,
|
|
181
|
+
port=args.ws_port,
|
|
182
|
+
pop_size=pop_size,
|
|
183
|
+
max_votes=max_votes,
|
|
184
|
+
mut_sigma=mut_sigma,
|
|
185
|
+
elite_frac=elite_frac,
|
|
186
|
+
crossover_rate=crossover_rate,
|
|
187
|
+
)
|
|
188
|
+
if not args.no_browser:
|
|
189
|
+
open_browser_when_ready(args.host, args.port)
|
|
190
|
+
|
|
191
|
+
os.environ["DET_START_WS"] = "1"
|
|
192
|
+
cmd = [__file__, "runserver", f"{args.host}:{args.port}"]
|
|
193
|
+
if use_noreload:
|
|
194
|
+
cmd.append("--noreload")
|
|
195
|
+
sys.argv = cmd
|
|
196
|
+
execute_from_command_line(cmd)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
if __name__ == "__main__":
|
|
200
|
+
main()
|