-
Notifications
You must be signed in to change notification settings - Fork 23
Draft visualizer #448
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
Draft visualizer #448
Conversation
Some Notes: |
Thank you for doing this. We currently have visualizer?: #command & =~"^/" & !~"\\{count" | null Should visualizer?: ["in" | "out"]: #command | null In particular the requirement that visualizer invocations start with But it’s not clear to me that this shall be specified in generators at all any more. When visualizer?: ["in" | "out"]: *true | false I can also see myself passing arguments to a visualizer, so maybe we want visualizer?: ["in" | "out"]: string | false instead? |
Agreed, the current (still didn't have time to look at the code in detail or try it out... just replying to Thore's suggestions, thanks for looking at this! ❤️) |
I don't think we need to specify anything in If you don't want to run it for some testgroup/test cases you can implemtent this via |
Even more basic question: what does |
If we'd strictly follow the spec, the resulting images of the input/output visualizer would not automatically end up in
So I don't think we need to disambiguate |
Short answer (in terms of BAPCtools): yes.
I don't see the need for this |
@mpsijm will you have time to take a look? |
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.
Thank you so much for picking this up! ❤️ I see a lot has changed, and the majority is looking very good 😄 Some nit-pick comments or questions below 🙂
I didn't test super extensively, but I'm very happy that @thorehusfeldt also took the time to write some visualizers! ❤️
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.
In https://icpc.io/problem-package-format/spec/2023-07-draft.html#reporting-additional-feedback, it is mentioned that the output validator can also write image files to the feedback directory. Currently, bt generate
only runs the answer validator, but I guess that we may also want to run the output validator on the .ans
file, if an output validator exists? I think this could be added to TestcaseRule.validate_ans_and_out
?
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.
this already happens right?
if there is a .out
we run the output validator and if there ans_is_output
is true the output validator is used as answer validator and therefore also run.
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.
Sure, but I'm talking about the case where a .out
file does not exist, which is the case for all secret test cases.
Take for example Jib Job. Say that, as implementor of that problem, I want to visualize how the output of submissions looks like, and use this as test case image as well. This problem could have an output_visualizer
like this:
output_visualizer
#!/usr/bin/env python3
import sys
f = open(sys.argv[1]).readlines()
n = int(f[0])
team_jibs = list(map(int, sys.stdin.read().split()))
assert len(team_jibs) == n
xl, xh, yl, yh = 20000, -10000, 20000, -10000
cranes = []
for line, r in zip(f[1:], team_jibs):
x, y, h = map(int, line.split())
cranes.append((x, y, r))
xl = min(xl, x - r)
yl = min(yl, y - r)
xh = max(xh, x + r)
yh = max(yh, y + r)
w = xh - xl
h = yh - yl
if w > h:
h *= 1024 / w
w = 1024
else:
w *= 1024 / h
h = 1024
with open(sys.argv[3] + "/judgeimage.svg", "w") as of:
of.write(
f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="{xl} {yl} {xh - xl} {yh - yl}" width="{w}" height="{h}" style="fill:rgba(0,0,255,0.5)">'
)
for x, y, r in cranes:
of.write(f'<circle cx="{x}" cy="{y}" r="{r}" />')
of.write("</svg>")
I don't need an input_visualizer
(or "test case visualizer"), because it will do exactly the same as the output visualizer, with the difference that it would read from a fixed .ans
file, rather than read a submission's output from stdin.
Now, I could also decide to write similar code like this in the output validator instead, rather than having a separate output visualizer. But, currently, the output validator is not run during bt generate
for this problem.
(to test this, I currently just appended this to the main
function of the output validator of Jib Job, because I didn't feel like actually writing the same visualizer in C++ 😛)
ofstream vis(string(argv[3]) + "/judgeimage.svg");
vis << n << endl;
vis.close();
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.
in the case where .out
does not exist (and ans_is_out
) the output Validator should already be run (as well as any other answer validator)?
we just don't copy the image... at least thats how i understand the code right now
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.
mhm this is kind of ugly for hashing... we now have multiple programs that could create the same file... and we don't know which is actually responsible ^^' This would mean that if either validator or visualizer change both need to be rerun?
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.
I think even the current implementation of running the output_visualizer
is broken in regards to caching...
The output visualizer can read stuff written by the output_validator
but the curren't implementation can't guarantee that these files still exist...
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.
I have been thinking about this a lot and I think for interactive or multi-pass problems using the output_visualizer
is a bad idea since it visualized the solution which is not part of the testcase.
For ans_is_outout
problems or those with a .out
file we can use the feedback dir, we just have no guarantee in what order input, output, and answer validators were run...
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.
the
output_visualizer
[...] visualized the solution which is not part of the testcase
But it makes sense that the output visualizer visualizes a possible output that represents a solution, right?
we just have no guarantee in what order input, output, and answer validators were run...
Aren't we the ones writing the code? 😛 Especially during bt generate
: either all validators are run (and I assume in the order "input"-"answer"-"output"), or they are all suppressed with --no-validators
. I guess we could make --no-validators
imply --no-visualizer
because it may be the case that the visualizer reads files from the feedback dir that were left behind by the validators, but to be fair, this will probably not happen very often, so I don't think we need to add this restriction. It may go wrong in some rare cases, but I guess that's fine?
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.
Aren't we the ones writing the code? 😛
yes but there are these weird cases... for example if testcases are symlinked because of input:
. In that case some of the validators are rerun ^^
But it makes sense that the output visualizer visualizes a possible output that represents a solution, right?
not sure about this ^^' it probably depends on the kind of problem. for guess for example i think its quite strange to visualize a binary search?
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.
Yeah, I'm fine with not (fully) supporting visualizers for interactive test cases for now. Same as for the question of an output validator producing image files, we may want to document this somewhere 🙂
608b5b1
to
9aa7cd4
Compare
Co-authored-by: Maarten Sijm <[email protected]>
Co-authored-by: Maarten Sijm <[email protected]>
Co-authored-by: Maarten Sijm <[email protected]>
Updated the spec in Kattis/problem-package-format#439 (and hopefully also correctly updated BAPCtools accordingly, I'll check tomorrow if the tests passed) 😄 |
217eb03
to
0d2333f
Compare
Todo input visualizer:
bt upgrade
needs to readgenerators.yaml
, and if it has avisualizer:
key, move the target toinput_visualizer/
and remove it fromgenerators.yaml
. It should then warn that the visualizer itself needs to be rewritten to no longer read fromtestcase.in
, but from stdin.Program.visualizer
visualize.py
Todo output visualizers:
bt run
(andbt test
?) with a command-line argumentjudgeimage.<ext>
of the output visualizer can be copied back todata/
whenbt generate
runs it on the canonical jury solution, but only when there is no input visualizer, because there can be at most one image per test case.