Skip to content

Commit

Permalink
Fix some docs stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrrock2 committed Apr 28, 2024
1 parent 08b981c commit a833b5c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
51 changes: 49 additions & 2 deletions docs/repeated_subsections/reproducible_envs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ explorer (or by using the File menu) and selecting "New File".
 

Then, you will want to save the file with the extension ``.ipynb`` since we are making
a jupyter notebook. Then we will want to open the file and select the Python interpreter
a jupyter notebook. We can now open the file and select the Python interpreter
that we would like to use:


Expand All @@ -138,7 +138,8 @@ that we would like to use:
.. image:: ../user/images/vscode_tutorial/selecting_correct_venv.png
:align: center

And now we are done! We can now use all of the packages in our ``.venv`` virtual environment.
And now we are done! We can now use all of the packages in our ``.venv`` virtual environment
inside of our jupyter notebook:

.. image:: ../user/images/vscode_tutorial/show_gerrychain_import.png
:align: center
Expand Down Expand Up @@ -178,6 +179,52 @@ You will now see that the ``.venv`` is available in your list of kernels:
:align: center


.. warning::

As opposed to VSCode, Jupyter Lab does not automatically use the virtual environment that
you have in your project, so you will need to make sure that you have the correct kernel
installed before opening the lab. You can see which kernel you are using by looking at the
output of the following command:

.. code:: console
jupyter kernelspec list
this will output something like

.. code:: console
Available kernels:
.venv /Users/username/.local/share/jupyter/kernels/.venv
python3 /usr/local/share/jupyter/kernels/python3
You will then need to inspect the output of this command to see where the kernel is located.
In the above example, we can see that the kernel ``.venv`` is located at
``/Users/username/.local/share/jupyter/kernels/.venv`` which is the correct location for the
current working project. However, if we were to make a new project in
``/Users/username/Desktop/another_project`` and make a new virtual environment in this
location with the same name of ``.venv``, then, after running the command
``python -m ipykernel install --user --name=.venv``,
the kernel will still look like it is located at
``/Users/username/.local/share/jupyter/kernels/.venv``, BUT this new kernel is actually
the one for for the second project and not the original! This is important to note because
if you are working on multiple projects and you have the same kernel name for each project,
things can get a little confusing, so it is best to always reinstall the appropriate kernel
before opening the project in Jupyter.

Of course, an easy fix for this is to just use a different name for the kernel in each project.
For example, I might make my kernel name for the project in
``/Users/username/Desktop/gerrychain_docs``
``venv_gerrychain_docs`` via the command

.. code:: console
python -m ipykernel install --user --name=venv_gerrychain_docs
and the kernel name for the project in
``/Users/username/Desktop/another_project`` ``venv_another_project``.


We can now make a new notebook and select the kernel that we would like to use:

.. image:: ../user/images/jupyter_tutorial/make_new_file.png
Expand Down
6 changes: 2 additions & 4 deletions docs/user/optimizers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ And now we can run each of the optimization methods and collect some data!
# Tilted Runs
min_scores_tilt = np.zeros(total_steps)
for i, part in enumerate(optimizer.tilted_run(total_steps, p=0.125, with_progress_bar=true)):
for i, part in enumerate(optimizer.tilted_run(total_steps, p=0.125, with_progress_bar=True)):
min_scores_tilt[i] = optimizer.best_score
We can then plot the results to see how each method performed:
Expand Down Expand Up @@ -195,9 +195,7 @@ Likewise, the methods are similar as well:
scores_sb = np.zeros(total_steps)
for i, part in enumerate(gingles.short_bursts(10, 1000, with_progress_bar=True)):
max_scores_sb[i] = gingles.best_score
scores_sb[i] = gingles.score(part) min_scores_sb = np.zeros(total_steps)
for i, part in enumerate(gingles.short_bursts(5, 2000, with_progress_bar=True)):
min_scores_sb[i] = gingles.best_score
scores_sb[i] = gingles.score(part)
# Simulated Annealing
max_scores_anneal = np.zeros(total_steps)
Expand Down
5 changes: 3 additions & 2 deletions gerrychain/optimization/gingleator.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def reward_next_highest_close(
(or opportunity) district.
:type threshold: float
:returns: Number of opportunity districts + (1 - the next highest district's distance from
:returns: Number of opportunity districts +
(next highest district - (threshold - 0.1)) * 10
:rtype: float
"""
dist_percs = part[minority_perc_col].values()
Expand Down Expand Up @@ -188,7 +189,7 @@ def penalize_maximum_over(
(or opportunity) district.
:type threshold: float
:returns: Number of opportunity districts + (1 - the maximum excess)
:returns: Number of opportunity districts + (1 - the maximum excess) / (1 - threshold)
:rtype: float
"""
dist_percs = part[minority_perc_col].values()
Expand Down

0 comments on commit a833b5c

Please sign in to comment.