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.2.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.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_perf_env-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 19e767352bdb54309ca90e73cd20be5666314ca20ec1c1b76aa66ce43776af71
MD5 24b5a7e8b7041d6914c35ec967c46157
BLAKE2b-256 95d82a2ea39bc924d60f8d864585bbf6f7fd8b69ce010311a7333158e1cdfc55

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_perf_env-0.0.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for python_perf_env-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d85e1edb917fe7f87b3f597c16e7f8320bbb34273ca6536631eaea5283688e1e
MD5 b79e9cda4d56d685c9210ce2eee5b128
BLAKE2b-256 96144f39d990459414553bc2e76adbb98e81cd9e815ebbcd7fd667ba433a6d90

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_perf_env-0.0.2-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