Skip to content

Commit

Permalink
Merge pull request #138 from chrispyles/complexity
Browse files Browse the repository at this point in the history
Expose complexity checks without annotations
  • Loading branch information
leestott authored Dec 6, 2021
2 parents 489f821 + 3c77b63 commit af7b80b
Show file tree
Hide file tree
Showing 20 changed files with 507 additions and 108 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file, and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

* Added `TimeComplexityChecker` for analyzing complexity without annotations per [#137](https://github.com/microsoft/pybryt/issues/137)

## 0.3.1 - 2021-12-01

* Fixed a bug that was causing floats to be added to the memory footprint prematurely per resulting in [#125](https://github.com/microsoft/pybryt/issues/125)
Expand Down
56 changes: 46 additions & 10 deletions demo/fibonacci/fibonacci.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,40 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 848 µs, sys: 582 µs, total: 1.43 ms\n",
"Wall time: 1.4 ms\n"
"CPU times: user 69.8 ms, sys: 3.82 ms, total: 73.6 ms\n",
"Wall time: 75.6 ms\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:102: RuntimeWarning: divide by zero encountered in log2\n",
" return np.vstack((np.ones(len(n)), np.log2(n))).T\n",
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:122: RuntimeWarning: divide by zero encountered in log2\n",
" return np.vstack((np.ones(len(n)), n * np.log2(n))).T\n",
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:122: RuntimeWarning: invalid value encountered in multiply\n",
" return np.vstack((np.ones(len(n)), n * np.log2(n))).T\n"
]
},
{
"data": {
"text/plain": [
"pybryt.annotations.complexity.complexities.linear"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%time\n",
"checker = pybryt.TimeComplexityChecker(\"fib_runtime\")\n",
"for n in range(30):\n",
" with pybryt.check_time_complexity(\"fib_runtime\", n):\n",
" fibonacci(n, track=False)"
" with checker(n):\n",
" fibonacci(n, track=False)\n",
"checker.determine_complexity()"
]
},
{
Expand Down Expand Up @@ -191,16 +215,28 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 658 µs, sys: 11 µs, total: 669 µs\n",
"Wall time: 786 µs\n"
"CPU times: user 72.9 ms, sys: 2.49 ms, total: 75.4 ms\n",
"Wall time: 75.2 ms\n"
]
},
{
"data": {
"text/plain": [
"pybryt.annotations.complexity.complexities.linear"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%time\n",
"checker = pybryt.TimeComplexityChecker(\"fib_runtime\")\n",
"for n in range(30):\n",
" with pybryt.check_time_complexity(\"fib_runtime\", n):\n",
" fibonacci(n, track=False)"
" with checker(n):\n",
" fibonacci(n, track=False)\n",
"checker.determine_complexity()"
]
},
{
Expand Down Expand Up @@ -277,7 +313,7 @@
"_is_fork": false,
"celltoolbar": "Create Assignment",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -291,7 +327,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.7"
},
"toc": {
"colors": {
Expand Down
Binary file modified demo/fibonacci/fibonacci_no_recurse.pkl
Binary file not shown.
54 changes: 27 additions & 27 deletions demo/fibonacci/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -27,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -65,7 +65,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -74,6 +74,18 @@
"text": [
"0 1 1 2 3 5 8 13 21 34 0 1 1 2 3 5 8 13 21 34 "
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:102: RuntimeWarning: divide by zero encountered in log2\n",
" return np.vstack((np.ones(len(n)), np.log2(n))).T\n",
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:122: RuntimeWarning: divide by zero encountered in log2\n",
" return np.vstack((np.ones(len(n)), n * np.log2(n))).T\n",
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:122: RuntimeWarning: invalid value encountered in multiply\n",
" return np.vstack((np.ones(len(n)), n * np.log2(n))).T\n"
]
}
],
"source": [
Expand All @@ -93,7 +105,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -104,7 +116,7 @@
" 'submissions/subm03.ipynb']"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -124,7 +136,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -134,19 +146,19 @@
"Executing submissions/subm01.ipynb\n",
"Executing submissions/subm02.ipynb\n",
"Executing submissions/subm03.ipynb\n",
"CPU times: user 425 ms, sys: 176 ms, total: 601 ms\n",
"Wall time: 2min 5s\n"
"CPU times: user 518 ms, sys: 217 ms, total: 735 ms\n",
"Wall time: 2min 12s\n"
]
},
{
"data": {
"text/plain": [
"[<pybryt.student.StudentImplementation at 0x7fc0025d2e90>,\n",
" <pybryt.student.StudentImplementation at 0x7fbfa00d5290>,\n",
" <pybryt.student.StudentImplementation at 0x7fbfa00ee8d0>]"
"[<pybryt.student.StudentImplementation at 0x7f91289158d0>,\n",
" <pybryt.student.StudentImplementation at 0x7f9128915950>,\n",
" <pybryt.student.StudentImplementation at 0x7f91288fb550>]"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -170,23 +182,11 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:102: RuntimeWarning: divide by zero encountered in log2\n",
" return np.vstack((np.ones(len(n)), np.log2(n))).T\n",
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:122: RuntimeWarning: divide by zero encountered in log2\n",
" return np.vstack((np.ones(len(n)), n * np.log2(n))).T\n",
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:122: RuntimeWarning: invalid value encountered in multiply\n",
" return np.vstack((np.ones(len(n)), n * np.log2(n))).T\n"
]
},
{
"data": {
"text/plain": [
Expand Down Expand Up @@ -273,7 +273,7 @@
" ])]]"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -295,7 +295,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down
36 changes: 30 additions & 6 deletions demo/fibonacci/submissions/subm01.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -93,23 +93,47 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 19.4 ms, sys: 730 µs, total: 20.1 ms\n",
"Wall time: 20.3 ms\n"
"CPU times: user 47.5 ms, sys: 1.46 ms, total: 49 ms\n",
"Wall time: 48.3 ms\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:102: RuntimeWarning: divide by zero encountered in log2\n",
" return np.vstack((np.ones(len(n)), np.log2(n))).T\n",
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:122: RuntimeWarning: divide by zero encountered in log2\n",
" return np.vstack((np.ones(len(n)), n * np.log2(n))).T\n",
"/Users/chrispyles/opt/miniconda3/lib/python3.7/site-packages/pybryt/annotations/complexity/complexities.py:122: RuntimeWarning: invalid value encountered in multiply\n",
" return np.vstack((np.ones(len(n)), n * np.log2(n))).T\n"
]
},
{
"data": {
"text/plain": [
"pybryt.annotations.complexity.complexities.linear"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%time\n",
"checker = pybryt.TimeComplexityChecker(\"fib_runtime\")\n",
"for n in range(30):\n",
" with pybryt.check_time_complexity(\"fib_runtime\", n):\n",
" fibonacci(n)"
" with checker(n):\n",
" fibonacci(n)\n",
"checker.determine_complexity()"
]
},
{
Expand Down
10 changes: 6 additions & 4 deletions demo/fibonacci/submissions/subm02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@
],
"source": [
"%%time\n",
"checker = pybryt.TimeComplexityChecker(\"fib_runtime\")\n",
"for n in range(30):\n",
" with pybryt.check_time_complexity(\"fib_runtime\", n):\n",
" fibonacci(n)"
" with checker(n):\n",
" fibonacci(n)\n",
"checker.determine_complexity()"
]
},
{
Expand All @@ -126,7 +128,7 @@
"_is_fork": false,
"celltoolbar": "Create Assignment",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -140,7 +142,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.7"
},
"toc": {
"colors": {
Expand Down
10 changes: 6 additions & 4 deletions demo/fibonacci/submissions/subm03.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@
],
"source": [
"%%time\n",
"checker = pybryt.TimeComplexityChecker(\"fib_runtime\")\n",
"for n in range(30):\n",
" with pybryt.check_time_complexity(\"fib_runtime\", n):\n",
" fibonacci(n)"
" with checker(n):\n",
" fibonacci(n)\n",
"checker.determine_complexity()"
]
},
{
Expand All @@ -125,7 +127,7 @@
"_is_fork": false,
"celltoolbar": "Create Assignment",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -139,7 +141,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.7"
},
"toc": {
"colors": {
Expand Down
2 changes: 2 additions & 0 deletions docs/annotations/complexity_annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ To use these custom complexity classes, they can either be passed as the first a
pybryt.TimeComplexity(my_cplx.quartic, name="foo", addl_complexities=[my_cplx.factorial])
.. _complexity_annotation_cm:

Tracking Code Complexity
------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ Execution
.. automodule:: pybryt.execution
:members:
:undoc-members:


Complexity Analysis
-------------------

.. automodule:: pybryt.complexity
:members:
:undoc-members:
Loading

0 comments on commit af7b80b

Please sign in to comment.