Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulate #42

Merged
merged 6 commits into from Oct 31, 2019
Merged

Simulate #42

merged 6 commits into from Oct 31, 2019

Conversation

MaximeBouton
Copy link
Member

Change the simulate! function to return a vector of scenes. The function is faster, type stable, and the vector of scenes is easier to manipulate than the QueueRecord object.

@coveralls
Copy link

coveralls commented Oct 30, 2019

Coverage Status

Coverage decreased (-1.7%) to 79.95% when pulling df63314 on simulate into 5d6ecff on master.

src/behaviors/tim_2d_driver.jl Outdated Show resolved Hide resolved

function _run_callbacks(callbacks::C, rec::EntityQueueRecord{S,D,I}, roadway::R, models::Dict{I,M}, tick::Int) where {S,D,I,R,M<:DriverModel,C<:Tuple{Vararg{Any}}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we still need the QueueRecord version while rec is not deprecated?


veh_state_p = propagate(veh, a, roadway, timestep)

push!(scenes[tick + 1], Entity(veh_state_p, veh.def, veh.id))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use fill! and indexing [i] instead of empty! and push!? May be more efficient and kind of feels cleaner to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the push! function on the Frame objects is not allocating: https://github.com/sisl/Records.jl/blob/master/src/frames.jl#L56

I also thought fill! would be cleaner but it creates reference to the same scene object.

src/simulation/simulation.jl Show resolved Hide resolved
end

if !(callbacks === nothing) && _run_callbacks(callbacks, scenes, roadway, models, tick)
final_tick = tick + 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could probably get rid of the final_tick variable alltogether by using scenes = scenes[1:tick+1] here (or some other function for deleting remaining entries, ideally something that does not allocate new memory for scenes) and then simply returning return scenes at the end.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of deleting entries, since scenes can be given in arguments, would return scenes[1:tick+1] in the if statement work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, even better I'd say


simulate!(scene, roadway, models, n_steps, dt)

simulate!(scene, roadway, models, n_steps, dt, callbacks=(CollisionCallback(),))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to call both versions of simulate here? what exactly is being tested? Maybe at least test type stability with @inferred

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the tests, now it is checking that the callback is actually called and that the list of scenes is smaller than expected.

src/behaviors/lane_change_models.jl Outdated Show resolved Hide resolved
src/behaviors/lateral_driver_models.jl Outdated Show resolved Hide resolved
Copy link
Collaborator

@raunakbh92 raunakbh92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome idea! In fact, I was not using simulate! in my work and instead just running a loop that calls get_actions! and tick! and then pushes the updated scene into a list of scenes because the Queuerecord made my head hurt. So, this is brilliant. I am not a software engineering wizard like y'all so I don't have specific feedback on code speed or coding standards.

Also, it is great that now we have using Random within AutomotiveModels.jl.

@MaximeBouton
Copy link
Member Author

@raunakbh92 if you are not using QueueRecords anymore we should probably make a bigger PR to deprecate it.

@raunakbh92
Copy link
Collaborator

I am using the Trajdata type for working with NGSIM.jl. Not sure if that is dependent on QueueRecords?

@MaximeBouton MaximeBouton merged commit c8f9214 into master Oct 31, 2019
@MaximeBouton MaximeBouton deleted the simulate branch October 31, 2019 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants