Skip to content

Add convert_s function#18

Merged
zsunberg merged 9 commits intoJuliaPOMDP:masterfrom
yangyou95:master
May 31, 2025
Merged

Add convert_s function#18
zsunberg merged 9 commits intoJuliaPOMDP:masterfrom
yangyou95:master

Conversation

@yangyou95
Copy link
Contributor

It seems like there is no convert_s() function for the LaserTag problem.
Adding a convert_s() function, transforming a LTState to a vector.

add convert_s function
@yangyou95 yangyou95 changed the title Update LaserTag.jl Add convert_s function Dec 13, 2022
@codecov
Copy link

codecov bot commented Dec 17, 2022

Codecov Report

Base: 68.23% // Head: 67.62% // Decreases project coverage by -0.60% ⚠️

Coverage data is based on head (c18fa55) compared to base (60b14f6).
Patch coverage: 0.00% of modified lines in pull request are covered.

❗ Current head c18fa55 differs from pull request most recent head da28f02. Consider uploading reports for the commit da28f02 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
- Coverage   68.23%   67.62%   -0.61%     
==========================================
  Files          10       10              
  Lines         447      451       +4     
==========================================
  Hits          305      305              
- Misses        142      146       +4     
Impacted Files Coverage Δ
src/LaserTag.jl 72.72% <0.00%> (-7.28%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@zsunberg zsunberg left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for the contribution! As in the rocksample PR, can you add a test?

Please also see my inline comment.

Finally, as in rocksample, it would be great to add the convert_s for the opposite direction.

src/LaserTag.jl Outdated

# add a function to transform a LTState to a vector
function POMDPs.convert_s(T::Type{<:AbstractArray}, s::LTState, p::LaserTagPOMDP)
return convert(T, vcat(s.robot, s.opponent, [s.terminal]))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return convert(T, vcat(s.robot, s.opponent, [s.terminal]))
return convert(T, vcat(s.robot, s.opponent, s.terminal))

I don't think you need to create a vector with s.terminal in it. That will cause an additional allocation.

(additionally, I think vcat itself might cause an allocation, which is disappointing. You might be able to eliminate all allocations with StaticArrays, but that might take a bit of learning. There are many tools to track allocations including BenchmarkTools.@btime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info!

Copy link
Member

@zsunberg zsunberg left a comment

Choose a reason for hiding this comment

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

@yangyou95 if you would like to finish this PR - that would be helpful! I added one suggestion to avoid allocating an array, but the most important change still needed is to add tests! Let me know if you need pointers on how to do this!

src/LaserTag.jl Outdated

# transform a vector to a LTState
function POMDPs.convert_s(T::Type{LTState}, v::AbstractArray{Float64}, p::LaserTagPOMDP)
return LTState([v[1], v[2]], [v[3], v[4]], v[5])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return LTState([v[1], v[2]], [v[3], v[4]], v[5])
return LTState(Coord(v[1], v[2]), Coord(v[3], v[4]), v[5])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @zsunberg! Sorry, I totally forgot this change after Xmas... I updated and pushed it! Hope what did is correct.
Pls let me know if everything is ok.

@yangyou95 yangyou95 requested a review from zsunberg May 30, 2025 12:54
@yangyou95
Copy link
Contributor Author

Hi @zsunberg,

I’ve made a small update to the convert_s function to use SVector for better performance, and I also added corresponding tests in the runtests file.

Also, sorry for the long delay (about 2 years!) — I was caught up preparing for my PhD defense at the time.

Copy link
Member

@zsunberg zsunberg left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I hope that you passed your defense!

I just removed some comments that didn't add any additional clarification, and made the tests a bit more specific. Otherwise it looks good. I will merge once the tests pass.

@zsunberg zsunberg merged commit ef67105 into JuliaPOMDP:master May 31, 2025
3 checks passed
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.

2 participants