Restructure PIT library to support unified singletrack import namespace#14
Draft
Restructure PIT library to support unified singletrack import namespace#14
Conversation
Co-authored-by: nandantumu <[email protected]>
Co-authored-by: nandantumu <[email protected]>
Co-authored-by: nandantumu <[email protected]>
Co-authored-by: nandantumu <[email protected]>
Copilot
AI
changed the title
[WIP] Update notebook to use new PCT library structure
Restructure PIT library to support unified singletrack import namespace
Oct 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR restructures the PIT library to enable a cleaner, more unified import pattern for single track dynamics and related loss functions. Users can now import everything they need through a single namespace:
Changes Made
New Package Structure
Created a new
pit.dynamics.singletrackpackage that consolidates related functionality:pit/dynamics/singletrack/__init__.py- Exports all public API componentspit/dynamics/singletrack/dynamics.py- ContainsSingleTrackandSingleTrackModclassespit/dynamics/singletrack/loss.py- Contains loss functions (yaw_normalized_loss, etc.) and constantsExported Components
The new package exports:
SingleTrack,SingleTrackModyaw_normalized_loss,yaw_normalized_loss_per_item,yaw_normalized_loss_per_elementANGLE_INDICES,non_angle_indicesUpdated Notebooks
Updated the following notebooks to use the new import pattern:
bin/ModelFitting.ipynbbin/AWSIM_Model_Fitting.ipynbDocumentation
Added comprehensive documentation:
Benefits
st.prefixfrom pit.dynamics.single_track import SingleTrack) continue to workDesign Philosophy
Following the requirements, this implementation:
Before vs After
Before:
After:
Testing
All structural validations pass:
Original prompt
Please ensure that this notebook functions under the changes made to the structure of the PCT library. I would like to use the notation "import pct.dynamics.singletrack as st", and use st. yaw_normalized_loss, .etc Keep the structure as simple and minimal as possible. Do as little error handling as possible.
The following is a snapshot of a chat conversation between a user and an AI coding assistant. Prioritize later messages in the conversation.
User: Please ensure that this notebook functions under the changes made to the structure of the PCT library. I would like to use the notation "import pct.dynamics.singletrack as st", and use st. yaw_normalized_loss, .etc
AI: I'll open the notebook to find the import cells and usages so I can update them to use "import pct.dynamics.singletrack as st" and ensure sys.path points to the package src; expected outcome: identify cells to edit and then update the notebook. I'll read the notebook file first.
AI: I'll search the PCT package for definitions of the loss functions (to reference them correctly), then I'll update the notebook imports and usages. I'll run a workspace search to find "yaw_normalized_loss".
AI: I'll list the files under the PCT src package to find where losses and singletrack modules live.
AI: I'll list the singletrack package files to see available symbols and whether
AI: exists.
AI: We need to enable importing as "import pct.dynamics.singletrack as st" and access functions like st.yaw_normalized_loss. Currently
AI: defines functions; but there is no
AI: in singletrack folder. Python package import requires package directories with
AI: or using namespace packages if using pkgutil; but simpler to add an
AI: in src/pct/dynamics/singletrack exporting the functions. Also ensure top-level package
pct.dynamicsimports singletrack module or allows subpackage import. Let's open src/pct/dynamics directory.AI: I saw earlier that in the notebook they import "from pct.dynamics import vehicle_dynamics_ks" which implies
pct.dynamicsmodule exists atAI: rather than package. Let's search for src/pct/dynamics.py.
AI: The top-level
pctpackageAI: imports from
.dynamicsand.loss, but these modules may have been reorganized into subpackages. Currently there is noAI: nor
AI: . The notebook currently imports from
pct.dynamicsandpct.lossat top. But after restructuring, these are inpct/dynamics/singletrack/...andAI: . So need to restore backward-compatible imports: create
AI: and
AI: that re-export functions from the new locations. Alternatively, modify notebook to import
pct.dynamics.singletrackas st andst.yaw_normalized_lossetc. The user requested specifically to "ensure notebook functions under changes" and "use notation import pct.dynamics.singletrack as st and use st.yaw_normalized_loss, etc." So modify the notebook to use that import, and also ensure thatsys.pathis set to include the packagesrcbefore importing local package. The notebook already imports pct.* successfully? It currently uses "from pct.dynamics import vehicle_dynamics_ks" and others. But user wants to change to "import pct.dynamics.singletrack as st" and use st.yaw_normalized_loss etc. So we should update the notebook's import cells to:.../PCT/srcto sys.path or uses pip editable install. Simpler to add:import sys, os
sys.path.insert(0, str(Path(file).resolve().parents[1]/'src')) but in notebooks Path(file) doesn't exist. Better to compute base path relative to notebook file: Path.cwd() maybe. The notebook is in
AI: . So we can set:
repo_root = Path('/home/nandan/SourceCode/PIVOT/PCT') or compute Path('..').resolve() but Jupyter working directory is probably repo root when opening; safe approach: add sys.path insert of project src path:
from pathlib import Path
repo_root = Path.cwd().resolve()
src_path = repo_root / 'src'
if src_path.exists(): sys.path.insert(0, str(src_path))
But when notebook is run from different CWD, better to compute notebook file location via file not available. However often notebooks run with CWD = workspace root. But according to editorContext, notebook filepath is known; we can hardcode the absolute path of project's src: "/home/nandan/SourceCode/PIVOT/PCT/src". Use that.
Add import:
import sys
sys.path.insert(0, "/home/nandan/SourceCode/PIVOT/PCT/src")
Then import:
import pct.dynamics.singletrack as st
from pct.integrator import integrate_rk4
from pct.utils import Param, create_batched_params? But create_batched_params might be elsewhere. Let's inspect
AI: .
AI: Need to ensure Param is defined; likely in
AI: or in src/pct/utils elsewhere. Search for dataclass Param.
AI: I'm going to (1) add compatibility init files to make
pct.dynamics.singletrackimportable, and (2) update two notebook import cells to useimport pct.dynamics.singletrack as stand ensure the localsrcis onsys.path. Expected outcome: notebook imports the re...✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.