Skip to content

Duplicate tour and trip ids leads to failure in write_trip_matrices step #958

@Syonv

Description

@Syonv

Describe the bug
While testing the newest version of ActivitySim (1.4.0) with the MWCOG model, we encountered a crash in our write_trip_matrices step due to duplicate tour ids. The error message is as follows:

pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects

A possible source of this issue is that the dtype of the person_id column, i.e., the index of the persons table is no longer set to be a 64-bit integer, but a 32-bit integer, instead. When generating the tour_id (see canonical_ids.py:line414), the person_id is multiplied with the possible_tours_count variable, which, in our case, is around 40. Since the person_id column is a 32-bit integer the multiplication can result in an overflow, as there is no implicit cast for this type of operation. This leads to negative tour ids, which, though unique now, may lead to non-unique values later down the line (tour and trip ids) when used in different models or when new tour ids are generated.

We confirmed that that this might be an issue by explicitly casting the person_id column to a 64-bit integer in canonical_ids.py:line414. This led to the desired result, with unique, non-negative tour and trip ids, and ActivitySim did not crash.

Expected behavior
When generating a tour id, a unique, non-negative id should be generated and assigned accordingly, irrespective of how large the person id value may be or it's data type.

Additional context

  • Version 1.4.0 was initially tested without making any configuration changes to our ActivitySim 1.3.4 model setup.
  • As a potential fix, we tried setting the person id column explicitly to be a 64-bit integer when loading in the persons table, but that did not result in the desired outcome. Whenever the person_id column was extracted and used for another table, it was cast back to a 32-bit integer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working/bug f

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions