ambr 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.
- ambr-0.1.0/LICENSE +29 -0
- ambr-0.1.0/MANIFEST.in +6 -0
- ambr-0.1.0/PKG-INFO +202 -0
- ambr-0.1.0/README.md +138 -0
- ambr-0.1.0/architecture_diagram.png +0 -0
- ambr-0.1.0/requirements.txt +21 -0
- ambr-0.1.0/setup.cfg +4 -0
- ambr-0.1.0/setup.py +66 -0
- ambr-0.1.0/src/amber/__init__.py +105 -0
- ambr-0.1.0/src/amber/agent.py +65 -0
- ambr-0.1.0/src/amber/base.py +24 -0
- ambr-0.1.0/src/amber/environments.py +661 -0
- ambr-0.1.0/src/amber/experiment.py +148 -0
- ambr-0.1.0/src/amber/model.py +170 -0
- ambr-0.1.0/src/amber/optimization.py +682 -0
- ambr-0.1.0/src/amber/performance.py +557 -0
- ambr-0.1.0/src/amber/population.py +233 -0
- ambr-0.1.0/src/amber/sequences.py +209 -0
- ambr-0.1.0/src/ambr.egg-info/PKG-INFO +202 -0
- ambr-0.1.0/src/ambr.egg-info/SOURCES.txt +32 -0
- ambr-0.1.0/src/ambr.egg-info/dependency_links.txt +1 -0
- ambr-0.1.0/src/ambr.egg-info/requires.txt +34 -0
- ambr-0.1.0/src/ambr.egg-info/top_level.txt +1 -0
- ambr-0.1.0/tests/test_agent.py +186 -0
- ambr-0.1.0/tests/test_base.py +96 -0
- ambr-0.1.0/tests/test_environments.py +693 -0
- ambr-0.1.0/tests/test_experiment.py +393 -0
- ambr-0.1.0/tests/test_init.py +305 -0
- ambr-0.1.0/tests/test_integration.py +522 -0
- ambr-0.1.0/tests/test_model.py +323 -0
- ambr-0.1.0/tests/test_optimization.py +581 -0
- ambr-0.1.0/tests/test_performance.py +361 -0
- ambr-0.1.0/tests/test_population.py +41 -0
- ambr-0.1.0/tests/test_sequences.py +398 -0
ambr-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, AMBER Team
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
ambr-0.1.0/MANIFEST.in
ADDED
ambr-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ambr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Agent-Based Modeling Environment for Research
|
|
5
|
+
Home-page: https://github.com/amber-team/amber
|
|
6
|
+
Author: AMBER Team
|
|
7
|
+
Author-email: amber@example.com
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: polars>=0.20.0
|
|
23
|
+
Requires-Dist: numpy>=1.20.0
|
|
24
|
+
Requires-Dist: matplotlib>=3.3.0
|
|
25
|
+
Requires-Dist: seaborn>=0.11.0
|
|
26
|
+
Requires-Dist: networkx>=2.5
|
|
27
|
+
Requires-Dist: scikit-optimize>=0.9.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
|
32
|
+
Requires-Dist: coverage>=7.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: sphinx>=4.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: myst-parser>=0.18.0; extra == "dev"
|
|
36
|
+
Requires-Dist: nbsphinx>=0.8.0; extra == "dev"
|
|
37
|
+
Requires-Dist: nbconvert>=6.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: jupyter>=1.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
40
|
+
Requires-Dist: flake8>=5.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
42
|
+
Provides-Extra: advanced
|
|
43
|
+
Requires-Dist: smac>=2.0.0; extra == "advanced"
|
|
44
|
+
Requires-Dist: ConfigSpace>=0.7.1; extra == "advanced"
|
|
45
|
+
Requires-Dist: scikit-learn>=1.0.0; extra == "advanced"
|
|
46
|
+
Provides-Extra: docs
|
|
47
|
+
Requires-Dist: sphinx>=4.0.0; extra == "docs"
|
|
48
|
+
Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
|
|
49
|
+
Requires-Dist: myst-parser>=0.18.0; extra == "docs"
|
|
50
|
+
Requires-Dist: nbsphinx>=0.8.0; extra == "docs"
|
|
51
|
+
Requires-Dist: nbconvert>=6.0.0; extra == "docs"
|
|
52
|
+
Requires-Dist: jupyter>=1.0.0; extra == "docs"
|
|
53
|
+
Dynamic: author
|
|
54
|
+
Dynamic: author-email
|
|
55
|
+
Dynamic: classifier
|
|
56
|
+
Dynamic: description
|
|
57
|
+
Dynamic: description-content-type
|
|
58
|
+
Dynamic: home-page
|
|
59
|
+
Dynamic: license-file
|
|
60
|
+
Dynamic: provides-extra
|
|
61
|
+
Dynamic: requires-dist
|
|
62
|
+
Dynamic: requires-python
|
|
63
|
+
Dynamic: summary
|
|
64
|
+
|
|
65
|
+
# AMBER (Agent-based Modeling with Blazingly Efficient Records)
|
|
66
|
+
|
|
67
|
+
[](https://github.com/a11to1n3/AMBER/actions/workflows/ci.yml)
|
|
68
|
+
[](https://codecov.io/gh/a11to1n3/AMBER)
|
|
69
|
+
[](https://www.python.org/downloads/release/python-390/)
|
|
70
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
71
|
+
|
|
72
|
+
AMBER is a Python framework for agent-based modeling that uses Polars for efficient data handling and analysis. AMBER provides a clean, robust API for creating parallel, high-performance simulations in Python.
|
|
73
|
+
|
|
74
|
+
## 🚀 Performance
|
|
75
|
+
|
|
76
|
+
AMBER achieves high performance through its columnar memory layout (SoA), KD-Trees, and SIMD-vectorized operations.
|
|
77
|
+
|
|
78
|
+
**Benchmark vs Other Frameworks (5,000 Agents, 100 Steps)**
|
|
79
|
+
|
|
80
|
+
| Framework | Language | Architecture | Speed Rank |
|
|
81
|
+
|-----------|----------|--------------|------------|
|
|
82
|
+
| **Agents.jl** | Julia | Vectorized | 🥇 1st (0.02s - 0.9s) |
|
|
83
|
+
| **AMBER** | Python | Vectorized | 🥈 **2nd (0.1s - 2.3s)** |
|
|
84
|
+
| **SimPy (Dense)** | Python | Process/DES | 🥉 3rd (0.3s - 4.3s) |
|
|
85
|
+
| **Melodie** | Python | Hybrid | 4th (0.4s - 20s) |
|
|
86
|
+
| **AgentPy** | Python | Object | 5th (2s - 30s) |
|
|
87
|
+
| **Mesa** | Python | Object | 6th (50s - 30s) |
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
*\*SimPy is exceptionally fast for sparse models (like SIR) due to its event-driven nature, but AMBER is faster for dense/movement-heavy models.*
|
|
91
|
+
|
|
92
|
+
AMBER is the **state-of-the-art for dense simulation** in Python, while SimPy offers an alternative for event-driven logic.
|
|
93
|
+
|
|
94
|
+

|
|
95
|
+
|
|
96
|
+
## 🚀 Quick Start
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import amber as am
|
|
100
|
+
|
|
101
|
+
# Define a custom agent
|
|
102
|
+
class MyAgent(am.Agent):
|
|
103
|
+
def setup(self):
|
|
104
|
+
self.value = self.p.initial_value
|
|
105
|
+
|
|
106
|
+
def step(self):
|
|
107
|
+
self.value += self.model.random.randint(-1, 2)
|
|
108
|
+
self.record('value', self.value)
|
|
109
|
+
|
|
110
|
+
# Define a model
|
|
111
|
+
class MyModel(am.Model):
|
|
112
|
+
def setup(self):
|
|
113
|
+
self.agents = am.AgentList(self, self.p.agents, MyAgent)
|
|
114
|
+
|
|
115
|
+
def step(self):
|
|
116
|
+
self.agents.call('step')
|
|
117
|
+
|
|
118
|
+
def update(self):
|
|
119
|
+
super().update()
|
|
120
|
+
self.agents.record('value')
|
|
121
|
+
|
|
122
|
+
# Run a simulation
|
|
123
|
+
parameters = {
|
|
124
|
+
'agents': 10,
|
|
125
|
+
'initial_value': 5,
|
|
126
|
+
'steps': 100
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
model = MyModel(parameters)
|
|
130
|
+
results = model.run()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## ⚡ Advanced: Vectorized Updates
|
|
134
|
+
|
|
135
|
+
For maximum performance, access the underlying `Population` manager to perform SIMD-vectorized state updates, bypassing Python loop overhead:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
def step(self):
|
|
139
|
+
# Create a batch update context
|
|
140
|
+
with self.population.create_batch_context() as batch:
|
|
141
|
+
# Queue updates logic (executed in Rust/Polars)
|
|
142
|
+
batch.add_update(target_ids, 'wealth', 1)
|
|
143
|
+
batch.add_update(source_ids, 'wealth', -1)
|
|
144
|
+
|
|
145
|
+
# State is applied atomically here
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 🔬 Optimization
|
|
149
|
+
|
|
150
|
+
AMBER includes powerful optimization capabilities for parameter tuning:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from amber.optimization import ParameterSpace, grid_search
|
|
154
|
+
|
|
155
|
+
# Define parameter space
|
|
156
|
+
parameter_space = ParameterSpace({
|
|
157
|
+
'agents': [10, 50, 100],
|
|
158
|
+
'initial_value': [1, 5, 10],
|
|
159
|
+
'steps': 100
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
# Run optimization
|
|
163
|
+
results = grid_search(MyModel, parameter_space, 'some_metric')
|
|
164
|
+
best_params = results[0]['parameters']
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 📦 Installation
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
pip install -e .
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 🏗️ Features
|
|
174
|
+
|
|
175
|
+
- **Simple API**: Intuitive interface for agent-based modeling
|
|
176
|
+
- **High Performance**: Efficient data handling with Polars DataFrames
|
|
177
|
+
- **Optimization**: Built-in parameter optimization with grid search, random search, and Bayesian optimization
|
|
178
|
+
- **Environments**: Support for grid, network, and continuous space environments
|
|
179
|
+
- **Experiments**: Run multiple simulations with parameter sampling
|
|
180
|
+
- **Random Number Generation**: Reproducible simulations with controlled randomness
|
|
181
|
+
|
|
182
|
+
## 📚 Examples
|
|
183
|
+
|
|
184
|
+
Working examples are available in the `examples/` directory:
|
|
185
|
+
|
|
186
|
+
- **Wealth Transfer Model**: Economic inequality simulation
|
|
187
|
+
- **Virus Spread Model**: Epidemiological SIR model
|
|
188
|
+
- **Flocking Simulation**: Boids flocking behavior
|
|
189
|
+
- **Forest Fire Model**: Cellular automata fire spread
|
|
190
|
+
- **Network Simulations**: Graph-based agent interactions
|
|
191
|
+
|
|
192
|
+
## 📖 Documentation
|
|
193
|
+
|
|
194
|
+
For detailed documentation, tutorials, and API reference, visit our documentation site.
|
|
195
|
+
|
|
196
|
+
## 🤝 Contributing
|
|
197
|
+
|
|
198
|
+
We welcome contributions! Please see our contributing guidelines for more information.
|
|
199
|
+
|
|
200
|
+
## 📄 License
|
|
201
|
+
|
|
202
|
+
This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details.
|
ambr-0.1.0/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# AMBER (Agent-based Modeling with Blazingly Efficient Records)
|
|
2
|
+
|
|
3
|
+
[](https://github.com/a11to1n3/AMBER/actions/workflows/ci.yml)
|
|
4
|
+
[](https://codecov.io/gh/a11to1n3/AMBER)
|
|
5
|
+
[](https://www.python.org/downloads/release/python-390/)
|
|
6
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
7
|
+
|
|
8
|
+
AMBER is a Python framework for agent-based modeling that uses Polars for efficient data handling and analysis. AMBER provides a clean, robust API for creating parallel, high-performance simulations in Python.
|
|
9
|
+
|
|
10
|
+
## 🚀 Performance
|
|
11
|
+
|
|
12
|
+
AMBER achieves high performance through its columnar memory layout (SoA), KD-Trees, and SIMD-vectorized operations.
|
|
13
|
+
|
|
14
|
+
**Benchmark vs Other Frameworks (5,000 Agents, 100 Steps)**
|
|
15
|
+
|
|
16
|
+
| Framework | Language | Architecture | Speed Rank |
|
|
17
|
+
|-----------|----------|--------------|------------|
|
|
18
|
+
| **Agents.jl** | Julia | Vectorized | 🥇 1st (0.02s - 0.9s) |
|
|
19
|
+
| **AMBER** | Python | Vectorized | 🥈 **2nd (0.1s - 2.3s)** |
|
|
20
|
+
| **SimPy (Dense)** | Python | Process/DES | 🥉 3rd (0.3s - 4.3s) |
|
|
21
|
+
| **Melodie** | Python | Hybrid | 4th (0.4s - 20s) |
|
|
22
|
+
| **AgentPy** | Python | Object | 5th (2s - 30s) |
|
|
23
|
+
| **Mesa** | Python | Object | 6th (50s - 30s) |
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
*\*SimPy is exceptionally fast for sparse models (like SIR) due to its event-driven nature, but AMBER is faster for dense/movement-heavy models.*
|
|
27
|
+
|
|
28
|
+
AMBER is the **state-of-the-art for dense simulation** in Python, while SimPy offers an alternative for event-driven logic.
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
## 🚀 Quick Start
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import amber as am
|
|
36
|
+
|
|
37
|
+
# Define a custom agent
|
|
38
|
+
class MyAgent(am.Agent):
|
|
39
|
+
def setup(self):
|
|
40
|
+
self.value = self.p.initial_value
|
|
41
|
+
|
|
42
|
+
def step(self):
|
|
43
|
+
self.value += self.model.random.randint(-1, 2)
|
|
44
|
+
self.record('value', self.value)
|
|
45
|
+
|
|
46
|
+
# Define a model
|
|
47
|
+
class MyModel(am.Model):
|
|
48
|
+
def setup(self):
|
|
49
|
+
self.agents = am.AgentList(self, self.p.agents, MyAgent)
|
|
50
|
+
|
|
51
|
+
def step(self):
|
|
52
|
+
self.agents.call('step')
|
|
53
|
+
|
|
54
|
+
def update(self):
|
|
55
|
+
super().update()
|
|
56
|
+
self.agents.record('value')
|
|
57
|
+
|
|
58
|
+
# Run a simulation
|
|
59
|
+
parameters = {
|
|
60
|
+
'agents': 10,
|
|
61
|
+
'initial_value': 5,
|
|
62
|
+
'steps': 100
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
model = MyModel(parameters)
|
|
66
|
+
results = model.run()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## ⚡ Advanced: Vectorized Updates
|
|
70
|
+
|
|
71
|
+
For maximum performance, access the underlying `Population` manager to perform SIMD-vectorized state updates, bypassing Python loop overhead:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
def step(self):
|
|
75
|
+
# Create a batch update context
|
|
76
|
+
with self.population.create_batch_context() as batch:
|
|
77
|
+
# Queue updates logic (executed in Rust/Polars)
|
|
78
|
+
batch.add_update(target_ids, 'wealth', 1)
|
|
79
|
+
batch.add_update(source_ids, 'wealth', -1)
|
|
80
|
+
|
|
81
|
+
# State is applied atomically here
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## 🔬 Optimization
|
|
85
|
+
|
|
86
|
+
AMBER includes powerful optimization capabilities for parameter tuning:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from amber.optimization import ParameterSpace, grid_search
|
|
90
|
+
|
|
91
|
+
# Define parameter space
|
|
92
|
+
parameter_space = ParameterSpace({
|
|
93
|
+
'agents': [10, 50, 100],
|
|
94
|
+
'initial_value': [1, 5, 10],
|
|
95
|
+
'steps': 100
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
# Run optimization
|
|
99
|
+
results = grid_search(MyModel, parameter_space, 'some_metric')
|
|
100
|
+
best_params = results[0]['parameters']
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 📦 Installation
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
pip install -e .
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 🏗️ Features
|
|
110
|
+
|
|
111
|
+
- **Simple API**: Intuitive interface for agent-based modeling
|
|
112
|
+
- **High Performance**: Efficient data handling with Polars DataFrames
|
|
113
|
+
- **Optimization**: Built-in parameter optimization with grid search, random search, and Bayesian optimization
|
|
114
|
+
- **Environments**: Support for grid, network, and continuous space environments
|
|
115
|
+
- **Experiments**: Run multiple simulations with parameter sampling
|
|
116
|
+
- **Random Number Generation**: Reproducible simulations with controlled randomness
|
|
117
|
+
|
|
118
|
+
## 📚 Examples
|
|
119
|
+
|
|
120
|
+
Working examples are available in the `examples/` directory:
|
|
121
|
+
|
|
122
|
+
- **Wealth Transfer Model**: Economic inequality simulation
|
|
123
|
+
- **Virus Spread Model**: Epidemiological SIR model
|
|
124
|
+
- **Flocking Simulation**: Boids flocking behavior
|
|
125
|
+
- **Forest Fire Model**: Cellular automata fire spread
|
|
126
|
+
- **Network Simulations**: Graph-based agent interactions
|
|
127
|
+
|
|
128
|
+
## 📖 Documentation
|
|
129
|
+
|
|
130
|
+
For detailed documentation, tutorials, and API reference, visit our documentation site.
|
|
131
|
+
|
|
132
|
+
## 🤝 Contributing
|
|
133
|
+
|
|
134
|
+
We welcome contributions! Please see our contributing guidelines for more information.
|
|
135
|
+
|
|
136
|
+
## 📄 License
|
|
137
|
+
|
|
138
|
+
This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details.
|
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Core dependencies
|
|
2
|
+
polars>=0.20.0
|
|
3
|
+
numpy>=1.20.0
|
|
4
|
+
networkx>=2.5
|
|
5
|
+
|
|
6
|
+
# Visualization
|
|
7
|
+
matplotlib>=3.3.0
|
|
8
|
+
seaborn>=0.11.0
|
|
9
|
+
|
|
10
|
+
# Optional optimization dependencies
|
|
11
|
+
scikit-optimize>=0.9.0
|
|
12
|
+
|
|
13
|
+
# Development and documentation dependencies (optional)
|
|
14
|
+
# Uncomment for development:
|
|
15
|
+
# pytest>=6.0.0
|
|
16
|
+
# pytest-cov>=2.0.0
|
|
17
|
+
# sphinx>=4.0.0
|
|
18
|
+
# sphinx-rtd-theme>=1.0.0
|
|
19
|
+
# myst-parser>=0.18.0
|
|
20
|
+
# nbsphinx>=0.8.0
|
|
21
|
+
# jupyter>=1.0.0
|
ambr-0.1.0/setup.cfg
ADDED
ambr-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="ambr",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
packages=find_packages(where="src"),
|
|
7
|
+
package_dir={"": "src"},
|
|
8
|
+
install_requires=[
|
|
9
|
+
"polars>=0.20.0",
|
|
10
|
+
"numpy>=1.20.0",
|
|
11
|
+
"matplotlib>=3.3.0",
|
|
12
|
+
"seaborn>=0.11.0",
|
|
13
|
+
"networkx>=2.5",
|
|
14
|
+
"scikit-optimize>=0.9.0",
|
|
15
|
+
],
|
|
16
|
+
extras_require={
|
|
17
|
+
"dev": [
|
|
18
|
+
"pytest>=7.0.0",
|
|
19
|
+
"pytest-cov>=4.0.0",
|
|
20
|
+
"pytest-mock>=3.10.0",
|
|
21
|
+
"coverage>=7.0.0",
|
|
22
|
+
"sphinx>=4.0.0",
|
|
23
|
+
"sphinx-rtd-theme>=1.0.0",
|
|
24
|
+
"myst-parser>=0.18.0",
|
|
25
|
+
"nbsphinx>=0.8.0",
|
|
26
|
+
"nbconvert>=6.0.0",
|
|
27
|
+
"jupyter>=1.0.0",
|
|
28
|
+
"black>=22.0.0",
|
|
29
|
+
"flake8>=5.0.0",
|
|
30
|
+
"mypy>=1.0.0",
|
|
31
|
+
],
|
|
32
|
+
"advanced": [
|
|
33
|
+
"smac>=2.0.0",
|
|
34
|
+
"ConfigSpace>=0.7.1",
|
|
35
|
+
"scikit-learn>=1.0.0",
|
|
36
|
+
],
|
|
37
|
+
"docs": [
|
|
38
|
+
"sphinx>=4.0.0",
|
|
39
|
+
"sphinx-rtd-theme>=1.0.0",
|
|
40
|
+
"myst-parser>=0.18.0",
|
|
41
|
+
"nbsphinx>=0.8.0",
|
|
42
|
+
"nbconvert>=6.0.0",
|
|
43
|
+
"jupyter>=1.0.0",
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
python_requires=">=3.8",
|
|
47
|
+
author="AMBER Team",
|
|
48
|
+
author_email="amber@example.com",
|
|
49
|
+
description="Agent-Based Modeling Environment for Research",
|
|
50
|
+
long_description=open("README.md").read(),
|
|
51
|
+
long_description_content_type="text/markdown",
|
|
52
|
+
url="https://github.com/amber-team/amber",
|
|
53
|
+
classifiers=[
|
|
54
|
+
"Development Status :: 4 - Beta",
|
|
55
|
+
"Intended Audience :: Science/Research",
|
|
56
|
+
"License :: OSI Approved :: BSD License",
|
|
57
|
+
"Programming Language :: Python :: 3",
|
|
58
|
+
"Programming Language :: Python :: 3.8",
|
|
59
|
+
"Programming Language :: Python :: 3.9",
|
|
60
|
+
"Programming Language :: Python :: 3.10",
|
|
61
|
+
"Programming Language :: Python :: 3.11",
|
|
62
|
+
"Programming Language :: Python :: 3.12",
|
|
63
|
+
"Topic :: Scientific/Engineering",
|
|
64
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
65
|
+
],
|
|
66
|
+
)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AMBER: Agent-Based Modeling Environment and Research Framework
|
|
3
|
+
|
|
4
|
+
A comprehensive Python framework for building, running, and analyzing agent-based models.
|
|
5
|
+
AMBER provides tools for creating complex simulations with agents, environments, and
|
|
6
|
+
sophisticated experimental workflows.
|
|
7
|
+
|
|
8
|
+
Key features:
|
|
9
|
+
- Flexible agent and model architecture
|
|
10
|
+
- Built-in environments (grid, space, network)
|
|
11
|
+
- Experiment management and parameter sweeping
|
|
12
|
+
- Optimization tools for model calibration
|
|
13
|
+
- High-performance data handling with Polars
|
|
14
|
+
|
|
15
|
+
Example:
|
|
16
|
+
>>> import amber as am
|
|
17
|
+
>>>
|
|
18
|
+
>>> class SimpleModel(am.Model):
|
|
19
|
+
... def setup(self):
|
|
20
|
+
... for i in range(10):
|
|
21
|
+
... agent = am.Agent(self, i)
|
|
22
|
+
... self.add_agent(agent)
|
|
23
|
+
...
|
|
24
|
+
... def step(self):
|
|
25
|
+
... self.record_model('agent_count', len(self.agents))
|
|
26
|
+
>>>
|
|
27
|
+
>>> model = SimpleModel({'steps': 5})
|
|
28
|
+
>>> results = model.run()
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from .agent import Agent
|
|
32
|
+
from .model import Model
|
|
33
|
+
from .population import Population, BatchUpdateContext
|
|
34
|
+
from .base import BaseModel, BaseAgent
|
|
35
|
+
from .sequences import AgentList
|
|
36
|
+
from .environments import GridEnvironment, SpaceEnvironment, NetworkEnvironment
|
|
37
|
+
from .experiment import Experiment, Sample, IntRange
|
|
38
|
+
from .optimization import (
|
|
39
|
+
ParameterSpace,
|
|
40
|
+
objective_function,
|
|
41
|
+
grid_search,
|
|
42
|
+
random_search,
|
|
43
|
+
bayesian_optimization,
|
|
44
|
+
SMACOptimizer,
|
|
45
|
+
MultiObjectiveSMAC,
|
|
46
|
+
SMACParameterSpace
|
|
47
|
+
)
|
|
48
|
+
from .performance import (
|
|
49
|
+
SpatialIndex,
|
|
50
|
+
ParallelRunner,
|
|
51
|
+
vectorized_move,
|
|
52
|
+
vectorized_wealth_transfer,
|
|
53
|
+
vectorized_random_velocities,
|
|
54
|
+
check_performance_deps,
|
|
55
|
+
HAS_SCIPY,
|
|
56
|
+
HAS_NUMBA,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
__version__ = '0.1.0'
|
|
60
|
+
__author__ = 'AMBER Team'
|
|
61
|
+
__email__ = 'amber@example.com'
|
|
62
|
+
__url__ = 'https://github.com/example/amber'
|
|
63
|
+
|
|
64
|
+
__all__ = [
|
|
65
|
+
'Agent',
|
|
66
|
+
'Model',
|
|
67
|
+
'Population',
|
|
68
|
+
'BatchUpdateContext',
|
|
69
|
+
'BaseModel',
|
|
70
|
+
'BaseAgent',
|
|
71
|
+
'AgentList',
|
|
72
|
+
'GridEnvironment',
|
|
73
|
+
'SpaceEnvironment',
|
|
74
|
+
'NetworkEnvironment',
|
|
75
|
+
'Experiment',
|
|
76
|
+
'Sample',
|
|
77
|
+
'IntRange',
|
|
78
|
+
'ParameterSpace',
|
|
79
|
+
'objective_function',
|
|
80
|
+
'grid_search',
|
|
81
|
+
'random_search',
|
|
82
|
+
'bayesian_optimization',
|
|
83
|
+
'SMACOptimizer',
|
|
84
|
+
'MultiObjectiveSMAC',
|
|
85
|
+
'SMACParameterSpace',
|
|
86
|
+
# Performance utilities
|
|
87
|
+
'SpatialIndex',
|
|
88
|
+
'ParallelRunner',
|
|
89
|
+
'vectorized_move',
|
|
90
|
+
'vectorized_wealth_transfer',
|
|
91
|
+
'vectorized_random_velocities',
|
|
92
|
+
'check_performance_deps',
|
|
93
|
+
'HAS_SCIPY',
|
|
94
|
+
'HAS_NUMBA',
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
# Clean up namespace - remove module references
|
|
98
|
+
import sys
|
|
99
|
+
_current_module = sys.modules[__name__]
|
|
100
|
+
for _name in list(globals().keys()):
|
|
101
|
+
if _name.startswith('_'):
|
|
102
|
+
continue
|
|
103
|
+
if _name not in __all__ and _name not in ['__version__', '__author__', '__email__', '__url__']:
|
|
104
|
+
delattr(_current_module, _name)
|
|
105
|
+
del _current_module, _name
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
import polars as pl
|
|
3
|
+
from .base import BaseAgent
|
|
4
|
+
|
|
5
|
+
class Agent(BaseAgent):
|
|
6
|
+
"""Base class for all agents in the simulation, using DataFrames for data storage."""
|
|
7
|
+
|
|
8
|
+
def __repr__(self):
|
|
9
|
+
"""String representation of the agent."""
|
|
10
|
+
return f"Agent(id={self.id})"
|
|
11
|
+
|
|
12
|
+
def setup(self):
|
|
13
|
+
"""Initialize agent attributes. Override this method in subclasses."""
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
def record(self, name: str, value: Any):
|
|
17
|
+
"""Record a variable value for this agent in the model's DataFrame.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
name: Name of the variable
|
|
21
|
+
value: Value to record
|
|
22
|
+
"""
|
|
23
|
+
# Add new column to model's DataFrame
|
|
24
|
+
self.model.agents_df = self.model.agents_df.with_columns([
|
|
25
|
+
pl.when(pl.col('id') == self.id)
|
|
26
|
+
.then(pl.lit(value))
|
|
27
|
+
.otherwise(pl.col(name))
|
|
28
|
+
.alias(name)
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
def get_data(self) -> pl.DataFrame:
|
|
32
|
+
"""Get this agent's data from the model's DataFrame.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
DataFrame containing this agent's data
|
|
36
|
+
"""
|
|
37
|
+
return self.model.agents_df.filter(pl.col('id') == self.id)
|
|
38
|
+
|
|
39
|
+
def update_data(self, data: Dict[str, Any]):
|
|
40
|
+
"""Update this agent's data in the model's DataFrame.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
data: Dictionary of column names and values to update
|
|
44
|
+
"""
|
|
45
|
+
for name, value in data.items():
|
|
46
|
+
self.model.agents_df = self.model.agents_df.with_columns([
|
|
47
|
+
pl.when(pl.col('id') == self.id)
|
|
48
|
+
.then(pl.lit(value))
|
|
49
|
+
.otherwise(pl.col(name))
|
|
50
|
+
.alias(name)
|
|
51
|
+
])
|
|
52
|
+
|
|
53
|
+
def get_neighbors(self, condition: Optional[pl.Expr] = None) -> pl.DataFrame:
|
|
54
|
+
"""Get neighboring agents' data based on a condition.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
condition: Optional Polars expression to filter neighbors
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
DataFrame containing neighboring agents' data
|
|
61
|
+
"""
|
|
62
|
+
neighbors = self.model.agents_df.filter(pl.col('id') != self.id)
|
|
63
|
+
if condition is not None:
|
|
64
|
+
neighbors = neighbors.filter(condition)
|
|
65
|
+
return neighbors
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional, List, Type
|
|
2
|
+
import polars as pl
|
|
3
|
+
import numpy as np
|
|
4
|
+
import random
|
|
5
|
+
|
|
6
|
+
class BaseModel:
|
|
7
|
+
"""Base class for all simulation models, using DataFrames for data storage."""
|
|
8
|
+
def __init__(self, parameters: Dict[str, Any]):
|
|
9
|
+
self.p = parameters
|
|
10
|
+
self.t = 0
|
|
11
|
+
self.agents_df = pl.DataFrame({'id': [], 't': []})
|
|
12
|
+
self.model_df = pl.DataFrame({'t': [0], **{k: [v] for k, v in parameters.items()}})
|
|
13
|
+
seed = parameters.get('seed', None)
|
|
14
|
+
self.random = random.Random(seed)
|
|
15
|
+
self.nprandom = np.random.default_rng(seed)
|
|
16
|
+
|
|
17
|
+
class BaseAgent:
|
|
18
|
+
"""Base class for all agents in the simulation, using DataFrames for data storage."""
|
|
19
|
+
def __init__(self, model: 'BaseModel', agent_id: int):
|
|
20
|
+
self.model = model
|
|
21
|
+
self.id = agent_id
|
|
22
|
+
self.p = model.p if model is not None else {}
|
|
23
|
+
|
|
24
|
+
|