Skip to main content

A Python package providing an environment for AI agents to test their code and receive detailed profiling feedback on execution time and memory usage. Facilitates performance analysis and optimization during AI development.

Project description

python-perf-env

PyPI version License

A Python package providing an environment for AI agents to test their code and receive detailed profiling feedback on execution time and memory usage.

Installation

Install the package using pip:

pip install python-perf-env

Quick Start / Get Started

This guide provides a quick introduction to using the python_perf_env package. It demonstrates how to create and interact with the SimpleEvaluator environment.

1. Import the necessary modules:

from python_perf_env import SimpleEvaluator

2. Create the environment:

You can create the environment using the default configuration:

env = SimpleEvaluator()

Or, you can customize the environment by providing a configuration dictionary:

# Say we want focused on optimizing algorithm on time
custom_config = {
    "max_input_len": 2048,
    "max_time_cost": 1,  # The maximum allowed execution time (in seconds)
    "max_memory_cost": 1 * GB,  # The maximum allowed memory usage (in bytes)
    "time_weight": 2, # Weight for time cost in reward calculation (default: 1).
    "memory_weight": 0.5, # Weight for memory cost in reward calculation (default: 1).
    "entry_point": "my_function",
}
env_custom = SimpleEvaluator(config=custom_config)

3. Reset the environment:

Reset the environment to get the initial observation:

env.reset()

4. Define the code to be executed:

The code you submit to the environment must include a function with the name specified in the entry_point configuration where we setted "my_function" in the custom_config (defaults to "env_main").

code = """
import time

def my_function():
    start_time = time.time()
    for _ in range(1000000):
        pass  # Simulate some work
    end_time = time.time()
    return end_time - start_time  # Return the execution time
"""

5. Take a step in the environment:

Submit the Python code as an action to the step() method:

observation, reward, terminated, truncated, info = env.step(code)

print("Observation:")
print(observation)
print("Reward:", reward)

Further Information

  • Documentation: Refer to the docstrings within the code for detailed information about the SimpleEvaluator class, its attributes, and its methods.
  • Security: Always prioritize security when using this environment as it does not provide encapsulated environment for code execution. Consider providing secure environment using container in future versions.
  • Profiling Output: The format of the profiling output might need to be parsed by your AI agent.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_perf_env-0.0.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_perf_env-0.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file python_perf_env-0.0.1.tar.gz.

File metadata

  • Download URL: python_perf_env-0.0.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for python_perf_env-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d2594160f9d18fe02d1f48417b798b9f98899fcaffa33ad581ae003964c13d49
MD5 6e21ac80ef832121c500217d445c610b
BLAKE2b-256 ebd78aaa61536badc579e7afd653a83ae6c5447187713e7d01a09a4cb3620df6

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_perf_env-0.0.1.tar.gz:

Publisher: python-publish.yml on NewJerseyStyle/python-perf-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_perf_env-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_perf_env-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 751b73ab05f319f63868f460ba2802fe0c82ac1bae254798d2b2cf97ae640870
MD5 1ac11785961012f35e21b4aed2da8243
BLAKE2b-256 65aab2716016b1470e2b99860166cbad84000a03d3c5bc8a67124b4045e41cc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_perf_env-0.0.1-py3-none-any.whl:

Publisher: python-publish.yml on NewJerseyStyle/python-perf-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page