-
Notifications
You must be signed in to change notification settings - Fork 101
Add a CI job for JuliaC #3094
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
Open
blegat
wants to merge
5
commits into
master
Choose a base branch
from
bl/juliac-ci
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add a CI job for JuliaC #3094
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| name = "MyApp" | ||
| uuid = "4768c16f-14ab-4f22-afac-abe0e8586942" | ||
|
|
||
| [deps] | ||
| MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" | ||
|
|
||
| [compat] | ||
| MathOptInterface = "1" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Copyright (c) 2017: Miles Lubin and contributors | ||
| # Copyright (c) 2017: Google Inc. | ||
| # | ||
| # Use of this source code is governed by an MIT-style license that can be found | ||
| # in the LICENSE.md file or at https://opensource.org/licenses/MIT. | ||
|
|
||
| # !!! info | ||
| # There is a one-to-one correspondence between the `run_` functions in this | ||
| # module and the `test_` functions in test_juliac.jl. If you add to one, you | ||
| # must also add to the other. | ||
|
|
||
| module MyApp | ||
|
|
||
| import MathOptInterface as MOI | ||
|
|
||
| function @main(args::Vector{String})::Cint | ||
| @assert length(args) >= 1 | ||
| head = popfirst!(args) | ||
| if head == "--mathoptformat" | ||
| return run_mathoptformat(args) | ||
| end | ||
| return 1 # Incorrect head | ||
| end | ||
|
|
||
| function run_mathoptformat(args::Vector{String})::Cint | ||
| filename = only(args) | ||
| model = MOI.FileFormats.MOF.Model() | ||
| x = MOI.add_variable(model) | ||
| MOI.set(model, MOI.VariableName(), x, "x") | ||
| MOI.add_constraint(model, x, MOI.GreaterThan(0.0)) | ||
| f = MOI.ScalarNonlinearFunction( | ||
| :+, | ||
| Any[MOI.ScalarNonlinearFunction(:sin, Any[x]), 2, 3.0], | ||
| ) | ||
| c = MOI.add_constraint(model, f, MOI.LessThan(7.0)) | ||
| MOI.set(model, MOI.ConstraintName(), c, "c") | ||
| objective = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0) | ||
| MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) | ||
| MOI.set(model, MOI.ObjectiveFunction{typeof(objective)}(), objective) | ||
| open(io -> write(io, model), filename, "w") | ||
| return 0 | ||
| end | ||
|
|
||
| end # module MOFWriter |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Copyright (c) 2017: Miles Lubin and contributors | ||
| # Copyright (c) 2017: Google Inc. | ||
| # | ||
| # Use of this source code is governed by an MIT-style license that can be found | ||
| # in the LICENSE.md file or at https://opensource.org/licenses/MIT. | ||
|
|
||
| # !!! info | ||
| # There is a one-to-one correspondence between the `test_` functions in this | ||
| # module and the `run_` functions in MyApp.jl. If you add to one, you must | ||
| # also add to the other. | ||
|
|
||
| # !!! info | ||
| # To run this file, you must first instantiate the MyApp Project.toml so | ||
| # that it includes MathOptInterface from the source code. From the root, do: | ||
| # ```julia | ||
| # using Pkg | ||
| # Pkg.develop(PackageSpec(path=pwd())) | ||
| # Pkg.instantiate() | ||
| # ``` | ||
| module TestJuliaC | ||
|
|
||
| using Test | ||
|
|
||
| import JSON | ||
| import JuliaC | ||
|
|
||
| function compile() | ||
| output_dir = mktempdir() | ||
| outname = joinpath(output_dir, "MyApp") | ||
| image_recipe = JuliaC.ImageRecipe( | ||
| output_type = "--output-exe", | ||
| file = joinpath(@__DIR__, "MyApp"), | ||
| trim_mode = "no", | ||
| add_ccallables = false, | ||
| verbose = true, | ||
| ) | ||
| link_recipe = JuliaC.LinkRecipe(; image_recipe, outname) | ||
| bundle_recipe = JuliaC.BundleRecipe(; link_recipe, output_dir) | ||
| JuliaC.compile_products(image_recipe) | ||
| JuliaC.link_products(link_recipe) | ||
| JuliaC.bundle_products(bundle_recipe) | ||
| return output_dir | ||
| end | ||
|
|
||
| function runtests() | ||
| output_dir = compile() | ||
| is_test(name) = startswith("$name", "test_") | ||
| @testset "$name" for name in filter(is_test, names(@__MODULE__; all = true)) | ||
| getfield(@__MODULE__, name)(output_dir) | ||
| end | ||
| return | ||
| end | ||
|
|
||
| function test_mathoptformat(output_dir) | ||
| # Run via the compiled binary | ||
| output = joinpath(output_dir, "compiled.mof.json") | ||
| run(`$(output_dir)/bin/MyApp --mathoptformat $output`) | ||
| # Compare against running as `-m` | ||
| reference = joinpath(output_dir, "reference.mof.json") | ||
| project = joinpath(@__DIR__, "MyApp") | ||
| run( | ||
| `$(Base.julia_cmd()) --project=$project -m MyApp --mathoptformat $reference`, | ||
| ) | ||
| @test read(output, String) == read(reference, String) | ||
| # Manually test the output | ||
| object = JSON.parsefile(output) | ||
| @test object["variables"] == [Dict("name" => "x")] | ||
| @test object["objective"] == Dict( | ||
| "sense" => "min", | ||
| "function" => Dict( | ||
| "type" => "ScalarAffineFunction", | ||
| "terms" => [Dict("coefficient" => 1.0, "variable" => "x")], | ||
| "constant" => 0.0, | ||
| ), | ||
| ) | ||
| con_c = Dict( | ||
| "name" => "c", | ||
| "function" => Dict( | ||
| "type" => "ScalarNonlinearFunction", | ||
| "root" => Dict("type" => "node", "index" => 2), | ||
| "node_list" => [ | ||
| Dict("type" => "sin", "args" => ["x"]), | ||
| Dict( | ||
| "type" => "+", | ||
| "args" => [Dict("type" => "node", "index" => 1), 2, 3.0], | ||
| ), | ||
| ], | ||
| ), | ||
| "set" => Dict("type" => "LessThan", "upper" => 7.0), | ||
| ) | ||
| con_bound = Dict( | ||
| "function" => Dict("type" => "Variable", "name" => "x"), | ||
| "set" => Dict("type" => "GreaterThan", "lower" => 0.0), | ||
| ) | ||
| @test object["constraints"] == [con_c, con_bound] | ||
| return | ||
| end | ||
|
|
||
| end # module TestJuliaC | ||
|
|
||
| TestJuliaC.runtests() | ||
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
Oops, something went wrong.
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.
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.
So there's a design question here: what's the point of testing this with
trim_mode = no? Shouldn't we test only withsafeorunsafe-warn? I don't see how writing a JSON file can ever be type-stable.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'm mimicking your approach with HiGHS of starting with
nothen fixing it. We can wait to have the required PRs though before merging this one. We can make it work if nothing is in theUniversalFallbackand we specialize onGenericModel.