Repository navigation
Conversation
With `--trim=no`, the JuliaC test does not check that the executable still works once it is trimmed. With `--trim=unsafe-warn`, JuliaC only compiles the methods it can reach from `main` through calls that it can infer, so a call that is dynamically dispatched fails at run time unless its method happens to be compiled for another reason. Like JuMPy does for its compiled backends, we first run MyApp in ordinary Julia with `--trace-dispatch` and every method that was dynamically dispatched to becomes an entry point of the image, see `entry.jl`. With this, the test passes without any change to the source code of MOI so the following PRs can focus on the code paths that the tracing does not cover.
The tracing only covers the code paths that the traced run actually executes. To test the code paths that it does not cover, we add commands to MyApp that are not traced. Each of them writes the traced model with one difference (a duplicate name, another objective type, ...) so that it tests exactly one code path that the tracing does not contain, and the test compares the file written by the executable with the one written by Julia. `_model` builds the traced model, `_run` runs a command with the executable and with Julia, and the outer testset makes sure that all commands are run even if one of them fails.
If the tracing does not contain a variable with a starting value, writing a MOF
file in which a variable has a starting value fails because methods are
missing. The objects of the variables and constraints were `NamedTuple`s whose
type depends on which fields are present, e.g., `(name = ..., primal_start =
...)`, and JSON writes each of these `NamedTuple` types with its own methods, so
every combination of fields would need to be traced.
The objects are now `JSON.Object{String,Any}` so JSON writes all of them with
the same methods, whatever their fields. An extension can still return a
`NamedTuple` from `moi_to_object`, JSON then writes it as before. This requires
JSON v1 for `JSON.Object`.
It is also faster since JSON doesn't need to specialize on each `NamedTuple`
type. Writing a model with 100,000 variables and 200,000 constraints (minimum
of 5 runs):
| | Time | Allocated |
| --- | --- | --- |
| `NamedTuple` (before) | 0.70 s | 725 MiB |
| `JSON.Object` (after) | 0.43 s | 409 MiB |
# Conflicts: # test/JuliaC/MyApp/src/MyApp.jl # test/JuliaC/test_juliac.jl
`Base.inferencebarrier` is not needed: in the varargs `_object`, Julia does not specialize on the type of each pair anyway, so the type of `value` is already unknown. What makes the insertion resolved at compile time is that the keys are declared as `String`, so a single method of `setindex!` matches. Without the barrier, the JuliaC test gives the same results.
Say which part of the document differs from the traced model, and refer to #3151 where they are introduced.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Writing a model with 100,000 variables and 200,000 constraints (minimum of 5 runs):
NamedTuple(before)JSON.Object(after)JSON.jsonis about 0.1 s in both cases, where we win is in building the objects.For instance,
moi_to_object(::ConstraintIndex, ...)builds each constraint's object as aVector{Pair{Symbol,Any}}, then callsNamedTuple(pairs). That computes theNamedTuple's type at run time, for each constraint.Also,
NamedTuple[]is aVectorwith an abstract element type, so every element written from it has a type known only at run time.It also helps with JuliaC compilation since we don't need to implement a different method for each
NamedTuple😇