Spring Challenge 2023 - questions about compiling to another language during setup turn

Due to a limitation in the way OCaml contributions are compiled (described here), I’m submitting a Python3 program which writes my OCaml solution to a file, compiles it properly, and then runs it.

This all has to happen during the setup turn, which I understand has a time limit of 1000ms. To check how much time I’m using, the Python script logs the time taken to write the file, and the time taken to compile it.

In the IDE, if I click “Replay in same conditions”, it reports that the compilation time is about 290ms. This is consistent with what I see locally.

However, if I click “Play my code”, or if I look at the output from the arena battles, it reports that the compilation time is between 2200ms and 3000ms - way over the time limit. However, it doesn’t time out. I’m imagining two possible reasons:

  • Most of that time is not actually used by the CPU and isn’t counted
  • The time limit is not enforced on the setup turn, or is enforced very loosely

My questions are:

  1. I’m using time.time() in Python3 to get the elapsed compilation time - is there a better way?
  2. If it’s not timing out now, is it likely that the rules will change later during the contest and suddenly this technique of compiling on the first turn will become un-viable?

Also, if any admin happens to see this and has the power to add to the OCaml compilation arguments, that would be amazing. Nothing new needs to be installed - after all, the Python3 script I’m submitting can compile my OCaml solution correctly on your servers. Without the Unix library, OCaml submissions can’t check the time in milliseconds, meaning that many of the interesting strategies for these contests are not possible in that language. The amended compiler command would have “unix.cmxa” added just before the source file, something like this:

ocamlopt -o /tmp/Answer unix.cmxa Answer.ml

Just in case: when you measure time, make sure to start your timer after you read your first input.

2 Likes

Thinking it through, this is very likely to be the issue I’m seeing. Testing and fixing it will take a bit of work, since the Python script will have to read the initial input, compile the real solution, then feed the input into it. Thank you!

You don’t necessarily need to do that, if you don’t require measuring the time.