Skip to content

Migrate from tic/toc timers and %time/%timeit to new Timer context manager #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 15, 2025

This PR migrates all timing code in the lecture series from legacy timing patterns to the new Timer context manager pattern in the quantecon package v0.9.0.

Changes Made

Updated timing patterns across multiple lectures:

  • lectures/numba.md: Migrated 6 instances of tic/toc usage
  • lectures/numpy.md: Migrated 4 instances of tic/toc usage + 4 instances of %time/%%time
  • lectures/parallelization.md: Migrated 4 instances of %time/%%time usage
  • lectures/jax_intro.md: Migrated 13 instances of %time/%%time usage

Migration patterns:

# Old tic/toc pattern for timing comparisons
qe.tic()
some_function()
time1 = qe.toc()

# New Timer pattern
with qe.Timer() as timer1:
    some_function()
time1 = timer1.elapsed
# Old %time/%timeit magic commands
%time some_operation()
%%time
some_operation()

# New Timer context manager
with qe.Timer():
    some_operation()

Note: All %timeit instances were correctly preserved as they serve a different purpose (benchmarking multiple runs vs single timing measurements).

Validation

  • All timing comparison logic preserved (speed gain calculations like time1 / time3 still work correctly)
  • Surrounding explanatory text remains accurate and relevant
  • Built and tested Jupyter notebook generation successfully with quantecon v0.9.0
  • Manual validation confirms Timer functionality works as expected across all updated lectures

The migration maintains full functionality while modernizing timing patterns to use the cleaner context manager approach with the official Timer implementation.

Fixes #390.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Migrate from tic,tac,toc timers to new Timer context manager in the quantecon package Migrate from tic/toc timers to new Timer context manager Aug 15, 2025
@Copilot Copilot AI requested a review from mmcky August 15, 2025 09:54
Copilot finished work on behalf of mmcky August 15, 2025 09:54
@mmcky
Copy link
Contributor

mmcky commented Aug 15, 2025

  • release quantecon then update this PR.

@mmcky
Copy link
Contributor

mmcky commented Aug 16, 2025

@copilot a new release of quantecon has been released that includes Timer (https://github.com/QuantEcon/QuantEcon.py/releases/tag/v0.9.0).

Can we please remove the fall back code as it is no longer needed.

Copy link
Contributor Author

Copilot AI commented Aug 16, 2025

@copilot a new release of quantecon has been released that includes Timer (https://github.com/QuantEcon/QuantEcon.py/releases/tag/v0.9.0).

Can we please remove the fall back code as it is no lon...

Removed the Timer fallback code from both lectures/numba.md and lectures/numpy.md since quantecon v0.9.0 is now available with native Timer support. The build validates successfully with the official Timer implementation. See commit 3a72aa5.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fred.stlouisfed.org
    • Triggering command: /usr/share/miniconda/envs/quantecon/bin/python -Xfrozen_modules=off -m ipykernel_launcher -f /tmp/tmp0y9rxjeo.json --HistoryManager.hist_file=:memory: (dns block)
  • jax.quantecon.org
    • Triggering command: /usr/share/miniconda/envs/quantecon/bin/python /usr/share/miniconda/envs/quantecon/bin/jb build lectures --path-output ./ -n -W --keep-going (dns block)
    • Triggering command: /usr/share/miniconda/envs/quantecon/bin/python /usr/share/miniconda/envs/quantecon/bin/jb build lectures --path-output ./ --builder=custom --custom-builder=jupyter -n -W --keep-going (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of mmcky August 16, 2025 23:36
Copy link

github-actions bot commented Aug 16, 2025

@github-actions github-actions bot temporarily deployed to pull request August 16, 2025 23:55 Inactive
@mmcky mmcky marked this pull request as ready for review August 17, 2025 01:45
@mmcky
Copy link
Contributor

mmcky commented Aug 17, 2025

@copilot please remove the silent=True from the numba lecture as it is useful to see the times as well as save the results. Thanks.

Copy link
Contributor Author

Copilot AI commented Aug 17, 2025

@copilot please remove the silent=True from the numba lecture as it is useful to see the times as well as save the results. Thanks.

Removed silent=True from all Timer instances in the numba lecture. The timers will now display timing output while still capturing the elapsed time for performance comparisons. See commit 93b664a.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fred.stlouisfed.org
    • Triggering command: /usr/share/miniconda/envs/quantecon/bin/python -Xfrozen_modules=off -m ipykernel_launcher -f /tmp/tmp3_7fivl2.json --HistoryManager.hist_file=:memory: (dns block)
  • jax.quantecon.org
    • Triggering command: /usr/share/miniconda/envs/quantecon/bin/python /usr/share/miniconda/envs/quantecon/bin/jb build lectures --path-output ./ -n -W --keep-going (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of mmcky August 17, 2025 02:24
@github-actions github-actions bot temporarily deployed to pull request August 17, 2025 02:44 Inactive
@mmcky
Copy link
Contributor

mmcky commented Aug 17, 2025

@copilot can you study the patterns I just made in 9538d56 and check if there are any other instances of %time or %%time in other lectures. Can we please update them?

@github-actions github-actions bot temporarily deployed to pull request August 17, 2025 05:20 Inactive
Copy link
Contributor Author

Copilot AI commented Aug 17, 2025

@copilot can you study the patterns I just made in 9538d56 and check if there ...

Found and converted all remaining instances of %time and %%time to qe.Timer() context manager following the patterns from commit 9538d56. Updated 4 lecture files:

  • lectures/numpy.md: 4 instances
  • lectures/parallelization.md: 4 instances
  • lectures/jax_intro.md: 13 instances

All %timeit instances were correctly preserved as they serve a different purpose (benchmarking multiple runs). Build validation confirms the Timer functionality works correctly. See commit b62cfc4.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fred.stlouisfed.org
    • Triggering command: /usr/share/miniconda/envs/quantecon/bin/python -Xfrozen_modules=off -m ipykernel_launcher -f /tmp/tmp9krjil4m.json --HistoryManager.hist_file=:memory: (dns block)
  • jax.quantecon.org
    • Triggering command: /usr/share/miniconda/envs/quantecon/bin/python /usr/share/miniconda/envs/quantecon/bin/jb build lectures --path-output ./ --builder=custom --custom-builder=jupyter -n -W --keep-going (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Migrate from tic/toc timers to new Timer context manager Migrate from tic/toc timers and %time/%timeit to new Timer context manager Aug 17, 2025
Copilot finished work on behalf of mmcky August 17, 2025 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate from tic,tac,toc timers to new Timer context manager in the quantecon package
2 participants