-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add "pretty printing" #13
Conversation
POMDPModelTools was renamed to POMDPTools. To ensure future compatibility, POMDPFiles needs to use POMDPTools.
States, actions, and observations are currently only printed numerically (thus making it difficult to know the corresponding state / action / observation). This adds the ability to (naïvely) pretty-print the "names" (via `Base.string`) of the state / action / observation.
Any opinions on this @zsunberg ? Does it make sense for it to be in |
I think it is a good idea to have here since it is a valid POMDP file format according to |
Cool. Let's do it. |
@jmuchovej make sure to mark this PR as not a work in progress when it is ready. In the long term, having a keyword argument for Ideally, someday, we would also be able to read files written with state names in and preserve the names in the POMDP representation, but that is probably for another day. |
Ooh. I see. Aside: it seems that If it were [re]defined, then perhaps that could be used instead of a keyword argument? (Though this seems unwieldy, it could something like... Base.write(io::IO, pomdp::POMDP) = ...
Base.write(io::IO, pomdpfile::POMDPFile) = ... So then it retains backwards compatibility, but sidesteps the need for the keyword argument.) Additionally, I just did some stuff with EzXML and they export a |
I don't think we need backwards compatibility since only one or two packages depend on this and semver makes it so that upgrading isn't terrible. I actually think that we should just copy |
Note that the CI tests are not passing, please take a look and see if you can fix it. |
5ed58e1
to
482ea10
Compare
482ea10
to
2ab8b76
Compare
POMDPModels is now a direct dependency because the package uses TabularPOMDP. We should use |
Oh! I see now. Completely missed that in |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #13 +/- ##
==========================================
+ Coverage 61.78% 65.60% +3.81%
==========================================
Files 3 3
Lines 280 314 +34
==========================================
+ Hits 173 206 +33
- Misses 107 108 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
This will need a bit more work before merging. See if you can fix the comments below. Then we can talk a bit more about what to name the functions.
There was a 20 `state`/`action`/`observation` cut-off for pretty printing (arbitrarily chosen). Instead, we should let people pick their poison. Additionally, we forced the use of `string`, but this should really be individual lambdas for each `state`/`action`/`observation` with a default that just enforces ASCII and strips repeating `_`.
I did some premature refactoring. They aren't exported at the moment, but I imagine they probably need to be. |
Rewrite exports so that `read_pomdp` is visible and remove `POMDPFile` export which is never defined anyway.
Referred to current observation by old var `obs` instead of the newer terse one `o`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmuchovej , thanks again for your contribution! This looks great! Would you be willing to make a test for this? Perhaps along the lines of
struct TestPOMDP <: POMDP{Int, Int, Int} end
POMDPs.states(::TestPOMDP) = (1,)
POMDPs.transition(::TestPOMDP) = Deterministic(1)
# etc.
@test sprint(POMDPFiles.write, TestPOMDP()) == """
<file contents>
"""
If you don't have time for that, no worries - I didn't ask you to do this up front. I will probably accept the PR anyways.
I think for function naming we should follow the convention of CSV.jl and have POMDPFiles.read
and POMDPFiles.write
that are differ. If you are willing to make that change, great! If not, I can do it. POMDPFiles.prettyprint
would be ok too if you want to have a separate function rather than just an option.
(I just pushed changes turning all the tabs into 4 spaces) |
Should we follow
Definitely! I might not get to this until later today or the weekend, though. Also, if the functions are changing, what other packages need to be updated? (I can look into this when writing tests, I just figured you might know offhand.) |
Oh, I did not know about FileIO! After an initial glance it seems like a good idea. I don't know enough to have a strong vote between FileIO and CSV, but my initial reaction is that FileIO might be better. |
|
Since we're going to go for the I'm down to the |
I like the way you're thinking, @jmuchovej !! I'm fine with accepting this with just the pretty printing and doing FileIO in another PR. I will merge this once the tests pass. |
Ok! I think these are all good to go now (tests and all). Also, I figure, since this is gonna be a short-lived series of functions, maybe there's no need for a patch bump? (Since the next one is gonna be a minor version bump anyway (afaik, Julia considers <1 minor bumps to be breaking).) |
Wow @jmuchovej , this has turned into quite a beautiful PR. Thank you for making such a high-quality contribution to this package!
Yes, I was just going to wait for FileIO to tag a new version. But if it is going to take you a while, then let me know and I can tag a version with just this. |
The POMDP file spec supports enum-like representation of
states
/actions
/observations
.Would this be an acceptable PR? (I did it for myself, but figured I'd add it upstream if y'all wanted it.)
Essentially, there's a "pretty printing" mode that uses the string representation of each
states
/actions
/observations
and uses those to generate a POMDP file. It does take the longer-form setup (1 line per pairing, vs. the matrix setup), but it's straightforward to support the matrices in the "pretty printing" mode.I did this before #10 was accepted, so I'll need to rebase, but figured I'd open the PR before rebasing.