PassengerSim¶
Below are a handful of top-level functions from the PassengerSim API. For most operations, please refer to the API reference for the individual sub-modules.
Modules¶
Callback hooks triggered at key points during a simulation. |
|
|
Configuration classes for PassengerSim simulations. |
Tools for building itinerary connections between flight legs. |
|
Compare results across multiple PassengerSim simulations. |
|
Low-level interface to the PassengerSim C++ simulation engine. |
|
Database interface for persisting and querying simulation results. |
|
Main simulation driver for PassengerSim. |
|
Run structured sets of PassengerSim simulations as experiments. |
|
|
Revenue management systems and algorithms for PassengerSim. |
This subpackage is for defining the SimulationTables class and its items. |
|
Tracers for recording detailed simulation data. |
|
This module provides various transformations for PassengerSim configurations. |
Functions¶
- passengersim.demo_network(name: str) Path[source]¶
Load a demo network configuration file.
A few demo networks are bundled with the PassengerSim package, and are always available to users.
- Parameters:
- name : str¶
The name of the network directory or a network file. If it is a directory, the function will look for a __main__.yaml file in that directory. Otherwise it will look for a file with the given name, with a .yaml or .yml extension. If the extension is not provided, it will be added automatically.
- Returns:
pathlib.Path – Path object pointing to the network configuration file.
Notes
The network name is converted to lowercase to handle case sensitivity differences between macOS (case-insensitive) and Linux (case-sensitive) file systems. All packaged network files are stored in lowercase.
- passengersim.demo_output(name: str) Path[source]¶
Load a demo output file.
A few demo output files are bundled with the PassengerSim package, and are always available to user, without needing to load or run a simulation.
- Parameters:
- name : str¶
The name of the output file, with or without the .pxsim extension. If the extension is not provided, it will be added automatically.
- Returns:
pathlib.Path – Path object pointing to the output file.
Notes
The output name is converted to lowercase to handle case sensitivity differences between macOS (case-insensitive) and Linux (case-sensitive) file systems. All output files are stored in lowercase.
- passengersim.demo_result(name: str, /) SimulationTables[source]¶
- passengersim.demo_result(networks: dict[str, str], /) Contrast
- passengersim.demo_result(**networks: str) Contrast
Load cached demo results, running networks as needed.
- Parameters:
- *args : str or dict[str, str]
One positional string names a demo network, as accepted by
demo_network(), and returns its results. Alternatively, one dictionary maps comparison labels to demo network names.- **networks : str¶
With no positional arguments, map comparison labels to demo network names. Cannot be combined with positional arguments.
- Returns:
SimulationTables or Contrast – A single string returns results loaded from a cached
.pxsimarchive. A dictionary or keyword arguments return aContrastcontaining results under the supplied labels. Detailed SQLite data is not retained. Close each result when finished with it.- Raises:
FileNotFoundError – The requested demo configuration does not exist.
OSError – The cache cannot be read or written.
TypeError – Arguments mix positional and keyword forms, contain more than one positional argument, or contain non-string labels or network names. Calling without any arguments is also invalid.
Notes
Archives are stored under
platformdirs.user_cache_dir("passengersim")in thedemo_resultssubdirectory, with one folder per PassengerSim version. Only the PassengerSim version and lowercased demo name determine the cache key. Configuration changes do not invalidate the cache; a new PassengerSim version gets a new cache entry. Each cache hit refreshes the archive’s modification time to record its last use. Auxiliary output files are disabled and any run database is temporary. Networks with more than one trial run usingMultiSimulation; single-trial networks useSimulation. Trials run in parallel worker processes from notebooks, interactive sessions, and platforms that fork workers. When called from a script file on platforms that spawn workers (macOS, Windows), trials run sequentially in the calling process, because an unguarded script would otherwise be re-executed by each worker. Delete the corresponding cache file to force a fresh simulation.The cache is shared by every environment of the same user, so it may hold results for several versions. At most once a week, a call that loads at least one demo also scans the cache and deletes the folder of any other PassengerSim version whose archives have not been used in about six months. The running version’s folder is never deleted by this scan. Failures while scanning or deleting are ignored.
Examples
>>> result = demo_result("europa") >>> comparison = demo_result(Europa="europa", ThreeMarket="3mkt/demo") >>> comparison = demo_result({"Europe": "europa", "Three markets": "3mkt/demo"})
- passengersim.from_file(path: str | Path | PathLike[str]) Config[source]¶
Load a PassengerSim file.
The type of file is determined by the extension. The following file types are supported:
.pxsim: SimulationTables
.yaml, .yml, or either also with .gz or .lz4: Config
- Parameters:
- path : str¶
Path to the file to load. The file type is determined by the extension.