CyberDSL
AI Cost Tracking
- 🤖 LLM usage: $0.7616 (2 commits)
- 👤 Human dev: ~$300 (3.0h @ $100/h, 30min dedup)
Generated on 2026-05-16 using openrouter/qwen/qwen3-coder-next
CyberDSL to biblioteka Python i mini-język dziedzinowy (DSL) do modelowania układów cybernetycznych: społeczności, grup, instytucji i relacji wpływu między nimi — wraz z symulacją krokową w czasie.
Instalacja
pip install -e .
# z opcjonalną wizualizacją:
pip install -e ".[viz]"
Składnia DSL
model:
name = "Miasto-A"
steps = 12
globals:
stress = 0.35
support = 0.55
nodes:
youth:group | state={cohesion:0.45, trust:0.40} | adaptability=0.70
elders:group | state={cohesion:0.60, trust:0.65} | adaptability=0.30
council:institution | state={cohesion:0.75, trust:0.50} | legitimacy=0.80
edges:
council->youth:influence | weight=0.30 | delay=1
youth->council:feedback | weight=0.25 | delay=0
elders->youth:stabilize | weight=0.20 | delay=1
rules:
youth.cohesion => clip(self['cohesion'] + 0.15*sum_influence - 0.10*globals['stress'])
youth.trust => clip(self['trust'] + 0.10*signals['w_council']*signals['sig_council'].get('cohesion',0))
council.trust => clip(self['trust'] + 0.12*signals['w_youth']*signals['sig_youth'].get('trust',0))
observables:
total_trust = (nodes['youth']['trust'] + nodes['elders']['trust'] + nodes['council']['trust']) / 3
Sekcje DSL
| Sekcja | Znaczenie |
|---|---|
model: |
Metadane: nazwa i liczba kroków |
globals: |
Parametry globalne (np. stress, support) |
nodes: |
Aktorzy, grupy, instytucje — ze stanami i parametrami |
edges: |
Kanały wpływu i sprzężenia zwrotnego z wagami i opóźnieniami |
rules: |
Równania aktualizacji stanu per węzeł per krok |
observables: |
Wskaźniki liczone na osi czasu |
Zmienne dostępne w regułach
| Zmienna | Opis |
|---|---|
self |
Aktualny stan węzła {var: float} |
params |
Parametry węzła |
globals |
Parametry globalne |
signals |
Sygnały wejściowe: sig_<src>, w_<src> |
sum_influence |
Ważona suma sygnałów wejściowych |
clip(x) |
Obcięcie do zakresu [0, 1] |
math |
Moduł math Pythona |
nodes |
Pełny słownik stanów wszystkich węzłów |
Użycie — kod DSL
from cyberdsl import ModelCompiler, Simulation
dsl = open('example.cyberdsl', encoding='utf-8').read()
model = ModelCompiler().parse(dsl)
sim = Simulation(model)
result = sim.run(steps=24)
print(result.summary())
print(result.observables_over_time())
Użycie — translacja opisu naturalnego (LiteLLM)
from cyberdsl import CommunityDSLTranslator, ModelCompiler, Simulation
description = """
Społeczność portowa ma trzy grupy: rybaków, młodzież i urząd miasta.
Rośnie stres ekonomiczny, ale działa lokalny program wsparcia.
Młodzież szybko reaguje na narrację urzędu, rybacy stabilizują normy społeczne.
"""
translator = CommunityDSLTranslator(model='openai/gpt-4o-mini', api_key='YOUR_KEY')
dsl = translator.translate(description)
model = ModelCompiler().parse(dsl)
result = Simulation(model).run(steps=16)
print(result.summary())
Interwencje i szoki
sim = Simulation(model)
sim.run(steps=4)
# Zewnętrzny szok — obniża zaufanie rybaków
sim.apply_shock('fishers', 'trust', -0.20)
# Zmiana parametru globalnego w połowie symulacji
sim.set_global('stress', 0.70)
result = sim.run(steps=8) # kontynuacja
API runtime
ModelCompiler
parse(dsl: str) -> ModelDef— parsuje i waliduje DSL.
Simulation(model)
run(steps=None) -> SimulationResult— uruchamia pełną symulację.step(step_no) -> dict— jeden krok ręcznie.apply_shock(node_id, var, delta)— interwencja zewnętrzna.set_global(key, value)— zmiana parametru globalnego.
SimulationResult
timeline— lista snapshotów{step, nodes, observables, globals}.summary() -> str— raport tekstowy.observables_over_time() -> dict[str, list[float]]— serie czasowe.node_state_over_time(node_id, var) -> list[float]— seria jednej zmiennej.
Architektura
cyberdsl/
├── parser.py # Leksykalny parser DSL → ModelDef
├── models.py # ModelCompiler + Simulation runtime
├── litellm_adapter.py # Translacja NL → DSL przez LLM
└── __init__.py # Public API
example.cyberdsl # Przykładowy model społeczności portowej
tests/
└── test_cyberdsl.py # 12 testów jednostkowych
Ograniczenia (v0.1)
- Parser liniowy, bez pełnego AST.
- Reguły ewaluowane przez
eval()— model DSL powinien pochodzić z zaufanego źródła. - Brak stochastyki, zdarzeń dyskretnych, kalibracji empirycznej.
- Brak eksportu do CSV / wykresów (planowane w v0.2).
Kierunki rozwoju
- Walidator i AST / bezpieczny interpreter wyrażeń.
- Sekcja
events:— zdarzenia, scenariusze, szoki zewnętrzne. - Eksport timeline do CSV i wykresów matplotlib.
- Kalibracja parametrów na danych empirycznych.
- Wieloagentowe rozszerzenia i symulacje Monte Carlo.
License
Licensed under Apache-2.0.
Metadata
Release files for cyberdsl 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cyberdsl-0.2.2.tar.gz | 36.1 kB | Without provenance | Details for cyberdsl-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cyberdsl-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for cyberdsl-0.2.2-py3-none-any.whl |
Total release size: 77.4 kB
Release files / cyberdsl-0.2.2.tar.gz
| Download URL | cyberdsl-0.2.2.tar.gz |
|---|---|
| Size | 36.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94e459b55d852329132a915edb431bb04bcd74f8cba31780dead164bc0f72566
|
|
BLAKE2b-256 checksum How to use checksums |
2ad8dc732a8fbc8469edb4a1c9a476f90c5a4021a531d6cecbf6fbeb6e89907b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / cyberdsl-0.2.2-py3-none-any.whl
| Download URL | cyberdsl-0.2.2-py3-none-any.whl |
|---|---|
| Size | 41.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a4b446d068bf7e1eddbc069eaf5b3b4960f1456e67f83dda932acad489051dc
|
|
BLAKE2b-256 checksum How to use checksums |
20ddea4e06eca4128b5f1ba4453b447099a9d3de7f097b2cf5bb1c69f63e8965
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for cyberdsl 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.