Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: codeflash-ai/codeflash
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.13.0
Choose a base ref
...
head repository: codeflash-ai/codeflash
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 10,606 additions and 3,301 deletions.
  1. +2 −6 .github/workflows/codeflash-optimize.yaml
  2. +3 −9 .github/workflows/end-to-end-test-benchmark-bubblesort.yaml
  3. +4 −9 .github/workflows/end-to-end-test-bubblesort-pytest-no-git.yaml
  4. +3 −8 .github/workflows/end-to-end-test-bubblesort-unittest.yaml
  5. +4 −9 .github/workflows/end-to-end-test-coverage.yaml
  6. +3 −8 .github/workflows/end-to-end-test-futurehouse.yaml
  7. +3 −8 .github/workflows/end-to-end-test-init-optim.yaml
  8. +3 −8 .github/workflows/end-to-end-test-tracer-replay.yaml
  9. +3 −8 .github/workflows/end-to-end-topological-sort-test.yaml
  10. +4 −5 .github/workflows/mypy.yml
  11. +2 −10 .github/workflows/unit-tests.yaml
  12. +1 −1 README.md
  13. +39 −0 code_to_optimize/code_directories/simple_tracer_e2e/workload.py
  14. +2 −2 codeflash/LICENSE
  15. +12 −2 codeflash/api/aiservice.py
  16. +70 −11 codeflash/api/cfapi.py
  17. +4 −0 codeflash/benchmarking/codeflash_trace.py
  18. +2 −0 codeflash/benchmarking/instrument_codeflash_trace.py
  19. +4 −0 codeflash/benchmarking/plugin/plugin.py
  20. +4 −0 codeflash/benchmarking/replay_test.py
  21. +2 −0 codeflash/benchmarking/utils.py
  22. +12 −18 codeflash/cli_cmds/cli.py
  23. +10 −1 codeflash/cli_cmds/cmd_init.py
  24. +28 −12 codeflash/cli_cmds/console.py
  25. +2 −2 codeflash/cli_cmds/logging_config.py
  26. +3 −1 codeflash/code_utils/checkpoint.py
  27. +199 −0 codeflash/code_utils/code_replacer.py
  28. +14 −2 codeflash/code_utils/code_utils.py
  29. +35 −9 codeflash/code_utils/compat.py
  30. +1 −0 codeflash/code_utils/config_consts.py
  31. +21 −1 codeflash/code_utils/config_parser.py
  32. +305 −0 codeflash/code_utils/edit_generated_tests.py
  33. +5 −6 codeflash/code_utils/env_utils.py
  34. +113 −13 codeflash/code_utils/formatter.py
  35. +20 −0 codeflash/code_utils/git_utils.py
  36. +3 −0 codeflash/code_utils/line_profile_utils.py
  37. +0 −28 codeflash/code_utils/remove_generated_tests.py
  38. +48 −0 codeflash/code_utils/time_utils.py
  39. +130 −22 codeflash/context/code_context_extractor.py
  40. +233 −1 codeflash/context/unused_definition_remover.py
  41. +277 −87 codeflash/discovery/discover_unit_tests.py
  42. +83 −13 codeflash/discovery/functions_to_optimize.py
  43. +5 −1 codeflash/models/models.py
  44. +105 −30 codeflash/optimization/function_optimizer.py
  45. +23 −9 codeflash/optimization/optimizer.py
  46. +16 −0 codeflash/picklepatch/pickle_patcher.py
  47. +1 −0 codeflash/picklepatch/pickle_placeholder.py
  48. +98 −8 codeflash/result/create_pr.py
  49. +162 −79 codeflash/tracer.py
  50. +1 −1 codeflash/tracing/profile_stats.py
  51. +2 −3 codeflash/verification/concolic_testing.py
  52. +3 −3 codeflash/version.py
  53. +2 −0 docs/docs/configuration.md
  54. +2 −2 docs/docs/optimizing-with-codeflash/benchmarking.md
  55. +1 −1 mypy_allowlist.txt
  56. +0 −2,689 poetry.lock
  57. +127 −80 pyproject.toml
  58. +1 −1 tests/scripts/end_to_end_test_tracer_replay.py
  59. +2 −2 tests/scripts/end_to_end_test_utilities.py
  60. +833 −0 tests/test_add_runtime_comments.py
  61. +655 −13 tests/test_code_context_extractor.py
  62. +950 −11 tests/test_code_replacement.py
  63. +350 −0 tests/test_existing_tests_source_for.py
  64. +591 −0 tests/test_formatter.py
  65. +243 −0 tests/test_function_discovery.py
  66. +5 −0 tests/test_git_utils.py
  67. +246 −1 tests/test_humanize_time.py
  68. +1 −2 tests/test_remove_functions_from_generated_tests.py
  69. +1 −1 tests/test_static_analysis.py
  70. +407 −0 tests/test_tracer.py
  71. +542 −44 tests/test_unit_test_discovery.py
  72. +1,433 −0 tests/test_unused_helper_revert.py
  73. +2,082 −0 uv.lock
8 changes: 2 additions & 6 deletions .github/workflows/codeflash-optimize.yaml
Original file line number Diff line number Diff line change
@@ -35,13 +35,9 @@ jobs:

- name: 📦 Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
uv sync
- name: ⚡️Codeflash Optimization
id: optimize_code
run: |
source .venv/bin/activate
poetry run codeflash --benchmark
uv run codeflash --benchmark
12 changes: 3 additions & 9 deletions .github/workflows/end-to-end-test-benchmark-bubblesort.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: end-to-end-test

on:
# Use pull_request_target for everything to ensure access to secrets
pull_request_target:
pull_request:
paths:
- '**' # Trigger for all paths

@@ -62,13 +61,8 @@ jobs:

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
uv sync
- name: Run Codeflash to optimize code
id: optimize_code_with_benchmarks
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_benchmark_sort.py
uv run python tests/scripts/end_to_end_test_benchmark_sort.py
13 changes: 4 additions & 9 deletions .github/workflows/end-to-end-test-bubblesort-pytest-no-git.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: end-to-end-test

on:
# Use pull_request_target for everything to ensure access to secrets
pull_request_target:
pull_request:
paths:
- '**' # Trigger for all paths

@@ -61,11 +60,8 @@ jobs:

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
uv sync
- name: Remove .git
run: |
if [ -d ".git" ]; then
@@ -85,5 +81,4 @@ jobs:
- name: Run Codeflash to optimize code
id: optimize_code
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_bubblesort_pytest.py
uv run python tests/scripts/end_to_end_test_bubblesort_pytest.py
11 changes: 3 additions & 8 deletions .github/workflows/end-to-end-test-bubblesort-unittest.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: end-to-end-test

on:
# Use pull_request_target for everything to ensure access to secrets
pull_request_target:
pull_request:
paths:
- '**' # Trigger for all paths

@@ -61,13 +60,9 @@ jobs:

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
uv sync
- name: Run Codeflash to optimize code
id: optimize_code
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_bubblesort_unittest.py
uv run python tests/scripts/end_to_end_test_bubblesort_unittest.py
13 changes: 4 additions & 9 deletions .github/workflows/end-to-end-test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Coverage E2E

on:
# Use pull_request_target for everything to ensure access to secrets
pull_request_target:
pull_request:
paths:
- '**' # Trigger for all paths

@@ -59,14 +58,10 @@ jobs:

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
poetry add black # my-best-repo in end_to_end_test_coverage.py is configured to use black
uv sync
uv add black # my-best-repo in end_to_end_test_coverage.py is configured to use black
- name: Run Codeflash to optimize code
id: optimize_code
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_coverage.py
uv run python tests/scripts/end_to_end_test_coverage.py
11 changes: 3 additions & 8 deletions .github/workflows/end-to-end-test-futurehouse.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: end-to-end-test

on:
# Use pull_request_target for everything to ensure access to secrets
pull_request_target:
pull_request:
paths:
- '**' # Trigger for all paths

@@ -61,13 +60,9 @@ jobs:

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
uv sync
- name: Run Codeflash to optimize code
id: optimize_code
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_futurehouse.py
uv run python tests/scripts/end_to_end_test_futurehouse.py
11 changes: 3 additions & 8 deletions .github/workflows/end-to-end-test-init-optim.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: end-to-end-test

on:
# Use pull_request_target for everything to ensure access to secrets
pull_request_target:
pull_request:
paths:
- '**' # Trigger for all paths
workflow_dispatch:
@@ -60,13 +59,9 @@ jobs:

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
uv sync
- name: Run Codeflash to optimize code
id: optimize_code
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_init_optimization.py
uv run python tests/scripts/end_to_end_test_init_optimization.py
11 changes: 3 additions & 8 deletions .github/workflows/end-to-end-test-tracer-replay.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: end-to-end-test

on:
# Use pull_request_target for everything to ensure access to secrets
pull_request_target:
pull_request:
paths:
- '**' # Trigger for all paths
workflow_dispatch:
@@ -61,13 +60,9 @@ jobs:

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
uv sync
- name: Run Codeflash to optimize code
id: optimize_code
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_tracer_replay.py
uv run python tests/scripts/end_to_end_test_tracer_replay.py
11 changes: 3 additions & 8 deletions .github/workflows/end-to-end-topological-sort-test.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: end-to-end-test

on:
# Use pull_request_target for everything to ensure access to secrets
pull_request_target:
pull_request:
paths:
- '**' # Trigger for all paths

@@ -86,13 +85,9 @@ jobs:

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
uv sync
- name: Run Codeflash to optimize code
id: optimize_code
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_topological_sort.py
uv run python tests/scripts/end_to_end_test_topological_sort.py
9 changes: 4 additions & 5 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -21,11 +21,10 @@ jobs:
with:
version: "0.5.30"

- name: install poetry as a tool
run: uv tool install poetry
- name: sync uv
run: |
uv sync
- name: install dependencies
run: uvx poetry install --with dev
- name: Run mypy on allowlist
run: uvx poetry run mypy --non-interactive --config-file pyproject.toml @mypy_allowlist.txt
run: uv run mypy --non-interactive --config-file pyproject.toml @mypy_allowlist.txt
12 changes: 2 additions & 10 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -25,17 +25,9 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
version: "0.5.30"
- name: install poetry as a tool
run: uv tool install poetry

- name: install dependencies
run: uvx poetry install --with dev
run: uv sync

- name: Unit tests
run: uvx poetry run pytest tests/ --cov --cov-report=xml --benchmark-skip -m "not ci_skip"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
if: matrix.python-version == '3.12.1'
with:
token: ${{ secrets.CODECOV_TOKEN }}
run: uv run pytest tests/ --benchmark-skip -m "not ci_skip"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -65,10 +65,10 @@ https://github.com/user-attachments/assets/38f44f4e-be1c-4f84-8db9-63d5ee3e61e5

Join our community for support and discussions. If you have any questions, feel free to reach out to us using one of the following methods:

- [Free live Installation Support](https://calendly.com/codeflash-saurabh/codeflash-setup)
- [Join our Discord](https://www.codeflash.ai/discord)
- [Follow us on Twitter](https://x.com/codeflashAI)
- [Follow us on Linkedin](https://www.linkedin.com/in/saurabh-misra/)
- [Email founders](mailto:saurabh@codeflash.ai)

## License

39 changes: 39 additions & 0 deletions code_to_optimize/code_directories/simple_tracer_e2e/workload.py
Original file line number Diff line number Diff line change
@@ -21,6 +21,45 @@ def test_threadpool() -> None:
for r in result:
print(r)

class AlexNet:
def __init__(self, num_classes=1000):
self.num_classes = num_classes
self.features_size = 256 * 6 * 6

def forward(self, x):
features = self._extract_features(x)

output = self._classify(features)
return output

def _extract_features(self, x):
result = []
for i in range(len(x)):
pass

return result

def _classify(self, features):
total = sum(features)
return [total % self.num_classes for _ in features]

class SimpleModel:
@staticmethod
def predict(data):
return [x * 2 for x in data]

@classmethod
def create_default(cls):
return cls()

def test_models():
model = AlexNet(num_classes=10)
input_data = [1, 2, 3, 4, 5]
result = model.forward(input_data)

model2 = SimpleModel.create_default()
prediction = model2.predict(input_data)

if __name__ == "__main__":
test_threadpool()
test_models()
4 changes: 2 additions & 2 deletions codeflash/LICENSE
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ Business Source License 1.1
Parameters

Licensor: CodeFlash Inc.
Licensed Work: Codeflash Client version 0.12.x
Licensed Work: Codeflash Client version 0.14.x
The Licensed Work is (c) 2024 CodeFlash Inc.

Additional Use Grant: None. Production use of the Licensed Work is only permitted
@@ -13,7 +13,7 @@ Additional Use Grant: None. Production use of the Licensed Work is only permitte
Platform. Please visit codeflash.ai for further
information.

Change Date: 2029-04-23
Change Date: 2029-06-09

Change License: MIT

14 changes: 12 additions & 2 deletions codeflash/api/aiservice.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

from codeflash.cli_cmds.console import console, logger
from codeflash.code_utils.env_utils import get_codeflash_api_key
from codeflash.code_utils.git_utils import get_last_commit_author_if_pr_exists, get_repo_owner_and_name
from codeflash.models.models import OptimizedCandidate
from codeflash.telemetry.posthog_cf import ph
from codeflash.version import __version__ as codeflash_version
@@ -97,6 +98,12 @@ def optimize_python_code( # noqa: D417
"""
start_time = time.perf_counter()
try:
git_repo_owner, git_repo_name = get_repo_owner_and_name()
except Exception as e:
logger.warning(f"Could not determine repo owner and name: {e}")
git_repo_owner, git_repo_name = None, None

payload = {
"source_code": source_code,
"dependency_code": dependency_code,
@@ -105,6 +112,9 @@ def optimize_python_code( # noqa: D417
"python_version": platform.python_version(),
"experiment_metadata": experiment_metadata,
"codeflash_version": codeflash_version,
"current_username": get_last_commit_author_if_pr_exists(None),
"repo_owner": git_repo_owner,
"repo_name": git_repo_name,
}

logger.info("Generating optimized candidates…")
@@ -118,7 +128,7 @@ def optimize_python_code( # noqa: D417

if response.status_code == 200:
optimizations_json = response.json()["optimizations"]
logger.info(f"Generated {len(optimizations_json)} candidates.")
logger.info(f"Generated {len(optimizations_json)} candidate optimizations.")
console.rule()
end_time = time.perf_counter()
logger.debug(f"Generating optimizations took {end_time - start_time:.2f} seconds.")
@@ -189,7 +199,7 @@ def optimize_python_code_line_profiler( # noqa: D417

if response.status_code == 200:
optimizations_json = response.json()["optimizations"]
logger.info(f"Generated {len(optimizations_json)} candidates.")
logger.info(f"Generated {len(optimizations_json)} candidate optimizations.")
console.rule()
return [
OptimizedCandidate(
Loading