Skip to content

Commit 171618d

Browse files
committed
Update modelsetup.rst
1 parent 77059ce commit 171618d

1 file changed

Lines changed: 42 additions & 11 deletions

File tree

‎docs/users-guide/modelsetup.rst‎

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,20 @@ Install UV
139139
We recommend installing UV as an independent tool on your machine, separate from any existing package managers you may have such as conda or pip.
140140

141141
For Windows users, run the following command in PowerShell to install *uv*. It does not require administrator privileges and installs *uv* for the current user only.
142-
by default, uv is installed to `~/.local/bin` directory. Usually, this is `C:/Users/<username>/.local/bin`.
142+
By default, uv is installed to `~/.local/bin` directory. Usually, this is `C:/Users/<username>/.local/bin`.
143+
143144
::
145+
144146
# Run the installer. Please review the printed message after installation.
145147
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
146148

147149
# Add uv to PATH
148150
$env:PATH = "$env:USERPROFILE\.local\bin;$env:Path"
149151

150152
If an agency wants to install *uv* globally for all users on Windows, run PowerShell as Administrator and run the following command.
153+
151154
::
155+
152156
# Run the installer with a custom install directory
153157
powershell -ExecutionPolicy ByPass -c {$env:UV_INSTALL_DIR = "C:\custom\install\directory";irm https://astral.sh/uv/install.ps1 | iex}
154158

@@ -158,20 +162,23 @@ If an agency wants to install *uv* globally for all users on Windows, run PowerS
158162
For more instructions on installing *uv* on Windows, MacOS, or Linux, please visit https://docs.astral.sh/uv/getting-started/installation/.
159163

160164
To verify that *uv* is installed correctly, open a new Command Prompt (not Anaconda Prompt) and run the following command.
165+
161166
::
162167

163168
uv --version
164169

165170
.. note::
166171
If you already have *uv* installed from an older project and you encounter errors
167172
such as
173+
168174
::
169175

170176
error: Failed to parse uv.lock... missing field version...
171177
172178
later in the process, you may need to update *uv* to the latest version by reinstalling it via the official
173179
installation script: https://docs.astral.sh/uv/getting-started/installation/#standalone-installer.
174180
You can check the version of *uv* you have installed by running
181+
175182
::
176183

177184
uv --version
@@ -187,9 +194,9 @@ The first is to use *uv* to install an official ActivitySim release from the Pyt
187194
The second is to use *uv* to install ActivitySim from the source code repository and use the dependency lockfile.
188195

189196
.. note::
190-
The first option (:ref:`From PyPI`) is the quickest way to install ActivitySim from an official release and is recommended for users who do not wish to change the Python code.
197+
The first option (:ref:`Option 1: From PyPI`) is the quickest way to install ActivitySim from an official release and is recommended for users who do not wish to change the Python code.
191198
However, they may end up using different deep dependencies than those tested by the developers.
192-
The second option (:ref:`From Source with Lockfile`) is recommended for users who may want to customize the Python code, and/or who want to run ActivitySim
199+
The second option (:ref:`Option 2: From Source with Lockfile`) is recommended for users who may want to customize the Python code, and/or who want to run ActivitySim
193200
exactly as it was tested by the developers using the dependency lockfile which results in the exact same deep dependencies.
194201

195202
The steps involved are described as follows.
@@ -286,7 +293,9 @@ Run ActivitySim with UV
286293
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287294

288295
Activate the virtual environment created by *uv*. This option is similar to using Python's classic venv or Conda env.
296+
289297
::
298+
290299
# cd into the project directory if not already there
291300
## if you used the From PyPI option
292301
cd asim_project
@@ -299,11 +308,13 @@ Activate the virtual environment created by *uv*. This option is similar to usin
299308
Once the virtual environment is activated, you can run ActivitySim commands directly using the `activitysim` command.
300309
For example, run the ActivitySim commandline using the following. More information about the commandline interface is available in
301310
the :ref:`Ways to Run the Model` section.
311+
302312
::
303313

304314
activitysim run -c configs -o output -d data
305315

306316
Alternatively, you can run ActivitySim commands directly using *uv* without activating the virtual environment.
317+
307318
::
308319

309320
uv run activitysim run -c configs -o output -d data
@@ -314,26 +325,33 @@ My travel demand model requires additional Python packages not included with Act
314325
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
315326
You can add additional packages to your *uv* project by using the `uv add` command. For example, to add the `geopandas` package,
316327
run the following command within your existing *uv* project directory.
328+
317329
::
330+
318331
# cd into your project directory
319332
cd asim_project
320333

321334
# Add geopandas package
322335
uv add geopandas
336+
323337
This will add the package to your virtual environment and update the `pyproject.toml` and the `uv.lock` file to include the new package and its dependencies.
324338

325339
If you envision having a version of Python packages that is different from the one used by ActivitySim, e.g., you need pandas 1.x for visualization (for some reason),
326340
we recommend creating a separate *uv* project for your custom packages and managing them independently from ActivitySim.
341+
327342
::
343+
328344
# Open Command Prompt
329345
mkdir viz_project
330346
cd viz_project
331347
uv init
332348
uv add pandas==1.5.3
333349

334-
Many agencies use commerical software that have Python APIs and dependencies that may conflict with ActivitySim dependencies.
335-
In such cases, we also recommend creating a separate *uv* project for the commerical software and managing them independently from ActivitySim.
350+
Many agencies use commercial software that have Python APIs and dependencies that may conflict with ActivitySim dependencies.
351+
In such cases, we also recommend creating a separate *uv* project for the commercial software and managing them independently from ActivitySim.
352+
336353
::
354+
337355
# Open Command Prompt
338356
mkdir emme_project
339357
cd emme_project
@@ -342,21 +360,34 @@ In such cases, we also recommend creating a separate *uv* project for the commer
342360

343361
How to share my working environment with others?
344362
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345-
You can share your working environment with others by sharing the `uv.lock` file located in your project directory.
346-
This file contains the exact versions of all packages and dependencies used in your project.
347-
Others can recreate the same environment by running the `uv sync --locked` command in a new project directory containing the shared `uv.lock` file.
363+
You can share your working environment with others by sharing the `uv.lock` file and the `pyproject.toml` file located in your project directory.
364+
The `uv.lock` file contains the exact versions of all packages and dependencies used in your project.
365+
Others can recreate the same environment by running the `uv sync --locked` command in a new project directory containing the shared files.
366+
348367
::
368+
369+
# Initialize a new project directory
370+
mkdir new_asim_project
371+
cd new_asim_project
372+
373+
# Copy .python-version file to new project directory (if exists)
374+
copy path\to\shared\.python-version .
375+
# Copy pyproject.toml file to new project directory
376+
copy path\to\shared\pyproject.toml .
349377
# Copy uv.lock file to new project directory
378+
copy path\to\shared\uv.lock .
379+
380+
# Recreate the same environment
350381
uv sync --locked
351382

352383
If I use the From PyPI option to install ActivitySim, would I run into dependency issues?
353384
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354-
Using the :ref:`From PyPI` option to install ActivitySim may result in different versions of deep dependencies than those tested by ActivitySim developers.
355-
This is because the :ref:`From PyPI` option installs only the direct dependencies listed in ActivitySim's `pyproject.toml` file,
385+
Using the :ref:`Option 1: From PyPI` option to install ActivitySim may result in different versions of deep dependencies than those tested by ActivitySim developers.
386+
This is because the :ref:`Option 1: From PyPI` option installs only the direct dependencies listed in ActivitySim's `pyproject.toml` file,
356387
and relies on *uv* to resolve and install the deep dependencies. It is likely that a newer version of ActivitySim deep dependencies
357388
may cause compatibility issues. For example, see this recent update with `numexpr`: https://github.com/pydata/numexpr/issues/540
358389

359-
When that happens, we recommend using the :ref:`From Source with Lockfile` option to install ActivitySim, which ensures that
390+
When that happens, we recommend using the :ref:`Option 2: From Source with Lockfile` option to install ActivitySim, which ensures that
360391
you are using the exact same deep dependencies as those tested by ActivitySim developers. In the meantime, you can also
361392
report the compatibility issues to the ActivitySim development team via GitHub Issues, so that they can address them in future releases.
362393

0 commit comments

Comments
 (0)