API Reference
Epochly API Reference: Context Managers
Context manager API reference: epochly.optimize(), epochly.monitor(), and block-level configuration.
Context managers for block-level optimization control.
optimize_context()
Apply optimization to a code block.
Signature
with epochly.optimize_context(level=1):# optimized code
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
level | int | 1 | Enhancement level (0-4) |
monitor_performance | bool | True | Enable performance monitoring |
Example
import epochlywith epochly.optimize_context(level=3):result = heavy_computation(data)
monitoring_context()
Add performance monitoring to a code block.
Signature
with epochly.monitoring_context(enable=True):# monitored code
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
enable | bool | True | Enable monitoring |
reset_on_exit | bool | False | Reset metrics on context exit |
jit_context()
Enable JIT compilation for a code block.
Signature
with epochly.jit_context():# JIT-compiled code
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
**options | Any | - | Additional JIT compilation options |
threading_context()
Enable threading optimization for a code block.
Signature
with epochly.threading_context(max_workers=None, thread_pool=True, **options):# threaded code
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
max_workers | int | None | Maximum thread count |
thread_pool | bool | True | Use thread pool |
**options | Any | - | Additional threading options |
benchmark_context()
Benchmark a code block.
Signature
with epochly.benchmark_context() as benchmark:# code to benchmarkprint(benchmark.results)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | 'benchmark' | Benchmark name |
print_results | bool | True | Print results on exit |