Skip to content

Commit 54f2c48

Browse files
authored
[FileFormats.MOF] update to v1.4 (#2169)
1 parent 0220b01 commit 54f2c48

File tree

8 files changed

+110
-9
lines changed

8 files changed

+110
-9
lines changed

docs/src/developer/checklists.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,32 @@ the model:
121121
- [ ] Implement `MOI.Utilities.final_touch(::Bridge, ::MOI.ModelLike)`
122122
- [ ] Ensure that `final_touch` can be called multiple times in a row
123123
```
124+
125+
## Updating MathOptFormat
126+
127+
Use this checklist when updating the version of MathOptFormat.
128+
129+
```
130+
## Basic
131+
132+
- [ ] The file at `src/FileFormats/MOF/mof.X.Y.schema.json` is updated
133+
- [ ] The constants `SCHEMA_PATH`, `VERSION`, and `SUPPORTED_VERSIONS` are
134+
updated in `src/FileFormats/MOF/MOF.jl`
135+
136+
## New sets
137+
138+
- [ ] New sets are added to the `@model` in `src/FileFormats/MOF/MOF.jl`
139+
- [ ] New sets are added to the `@enum` in `src/FileFormats/MOF/read.jl`
140+
- [ ] `set_to_moi` is defined for each set in `src/FileFormats/MOF/read.jl`
141+
- [ ] `head_name` is defined for each set in `src/FileFormats/MOF/write.jl`
142+
- [ ] A new unit test calling `_test_model_equality` is aded to
143+
`test/FileFormats/MOF/MOF.jl`
144+
145+
## Tests
146+
147+
- [ ] The version field in `test/FileFormats/MOF/nlp.mof.json` is updated
148+
149+
## Documentation
150+
151+
- [ ] The version fields are updated in `docs/src/submodules/FileFormats/overview.md`
152+
```

docs/src/submodules/FileFormats/overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ julia> print(read("file.mof.json", String))
9494
"name": "MathOptFormat Model",
9595
"version": {
9696
"major": 1,
97-
"minor": 3
97+
"minor": 4
9898
},
9999
"variables": [
100100
{
@@ -230,7 +230,7 @@ julia> good_model = JSON.parse("""
230230
{
231231
"version": {
232232
"major": 1,
233-
"minor": 3
233+
"minor": 4
234234
},
235235
"variables": [{"name": "x"}],
236236
"objective": {"sense": "feasibility"},
@@ -249,7 +249,7 @@ julia> bad_model = JSON.parse("""
249249
{
250250
"version": {
251251
"major": 1,
252-
"minor": 3
252+
"minor": 4
253253
},
254254
"variables": [{"NaMe": "x"}],
255255
"objective": {"sense": "feasibility"},

src/FileFormats/MOF/MOF.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import OrderedCollections
1111
import JSON
1212
import MathOptInterface as MOI
1313

14-
const SCHEMA_PATH = joinpath(@__DIR__, "mof.1.3.schema.json")
15-
const VERSION = v"1.3"
14+
const SCHEMA_PATH = joinpath(@__DIR__, "mof.1.4.schema.json")
15+
const VERSION = v"1.4"
1616
const SUPPORTED_VERSIONS =
17-
(v"1.3", v"1.2", v"1.1", v"1.0", v"0.6", v"0.5", v"0.4")
17+
(v"1.4", v"1.3", v"1.2", v"1.1", v"1.0", v"0.6", v"0.5", v"0.4")
1818

1919
const OrderedObject = OrderedCollections.OrderedDict{String,Any}
2020
const UnorderedObject = Dict{String,Any}
@@ -55,6 +55,7 @@ MOI.Utilities.@model(
5555
MOI.DualExponentialCone,
5656
MOI.NormOneCone,
5757
MOI.NormInfinityCone,
58+
MOI.NormCone,
5859
MOI.NormSpectralCone,
5960
MOI.NormNuclearCone,
6061
MOI.RelativeEntropyCone,
@@ -63,6 +64,7 @@ MOI.Utilities.@model(
6364
MOI.LogDetConeTriangle,
6465
MOI.LogDetConeSquare,
6566
MOI.PositiveSemidefiniteConeTriangle,
67+
MOI.ScaledPositiveSemidefiniteConeTriangle,
6668
MOI.PositiveSemidefiniteConeSquare,
6769
MOI.HermitianPositiveSemidefiniteConeTriangle,
6870
MOI.AllDifferent,
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/schema#",
3-
"$id": "https://jump.dev/MathOptFormat/schemas/mof.1.3.schema.json",
3+
"$id": "https://jump.dev/MathOptFormat/schemas/mof.1.4.schema.json",
44
"title": "The schema for MathOptFormat",
55
"type": "object",
66
"required": ["version", "variables", "objective", "constraints"],
@@ -11,7 +11,7 @@
1111
"required": ["minor", "major"],
1212
"properties": {
1313
"minor": {
14-
"enum": [0, 1, 2, 3]
14+
"enum": [0, 1, 2, 3, 4]
1515
},
1616
"major": {
1717
"const": 1
@@ -764,6 +764,19 @@
764764
"minimum": 1
765765
}
766766
}
767+
}, {
768+
"description": "The (vectorized) cone of symmetric positive semidefinite matrices, with `side_dimension` rows and columns, such that the off-diagonal entries are scaled by √2. The entries of the upper-right triangular part of the matrix are given column by column (or equivalently, the entries of the lower-left triangular part are given row by row).",
769+
"examples": ["{\"type\": \"ScaledPositiveSemidefiniteConeTriangle\", \"side_dimension\": 2}"],
770+
"required": ["side_dimension"],
771+
"properties": {
772+
"type": {
773+
"const": "ScaledPositiveSemidefiniteConeTriangle"
774+
},
775+
"side_dimension": {
776+
"type": "integer",
777+
"minimum": 1
778+
}
779+
}
767780
}, {
768781
"description": "The cone of symmetric positive semidefinite matrices, with side length `side_dimension`. The entries of the matrix are given column by column (or equivalently, row by row). The matrix is both constrained to be symmetric and to be positive semidefinite. That is, if the functions in entries `(i, j)` and `(j, i)` are different, then a constraint will be added to make sure that the entries are equal.",
769782
"examples": ["{\"type\": \"PositiveSemidefiniteConeSquare\", \"side_dimension\": 2}"],
@@ -1122,6 +1135,22 @@
11221135
"minimum": 1
11231136
}
11241137
}
1138+
}, {
1139+
"description": "The p-norm cone (t, x) ∈ {R^d : t ≥ (Σᵢ|xᵢ|^p)^(1/p)}.",
1140+
"examples": ["{\"type\": \"NormCone\", \"dimension\": 3, \"p\": 1.5}"],
1141+
"required": ["dimension", "p"],
1142+
"properties": {
1143+
"type": {
1144+
"const": "NormCone"
1145+
},
1146+
"dimension": {
1147+
"type": "integer",
1148+
"minimum": 1
1149+
},
1150+
"p": {
1151+
"type": "number"
1152+
}
1153+
}
11251154
}]
11261155
}
11271156
}

src/FileFormats/MOF/read.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ end
373373
GeometricMeanCone,
374374
NormOneCone,
375375
NormInfinityCone,
376+
NormCone,
376377
RelativeEntropyCone,
377378
NormSpectralCone,
378379
NormNuclearCone,
@@ -381,6 +382,7 @@ end
381382
LogDetConeTriangle,
382383
LogDetConeSquare,
383384
PositiveSemidefiniteConeTriangle,
385+
ScaledPositiveSemidefiniteConeTriangle,
384386
PositiveSemidefiniteConeSquare,
385387
HermitianPositiveSemidefiniteConeTriangle,
386388
ExponentialCone,
@@ -497,6 +499,10 @@ function set_to_moi(::Val{:NormInfinityCone}, object::Object)
497499
return MOI.NormInfinityCone(object["dimension"])
498500
end
499501

502+
function set_to_moi(::Val{:NormCone}, object::Object)
503+
return MOI.NormCone(object["p"], object["dimension"])
504+
end
505+
500506
function set_to_moi(::Val{:RelativeEntropyCone}, object::Object)
501507
return MOI.RelativeEntropyCone(object["dimension"])
502508
end
@@ -529,6 +535,13 @@ function set_to_moi(::Val{:PositiveSemidefiniteConeTriangle}, object::Object)
529535
return MOI.PositiveSemidefiniteConeTriangle(object["side_dimension"])
530536
end
531537

538+
function set_to_moi(
539+
::Val{:ScaledPositiveSemidefiniteConeTriangle},
540+
object::Object,
541+
)
542+
return MOI.ScaledPositiveSemidefiniteConeTriangle(object["side_dimension"])
543+
end
544+
532545
function set_to_moi(::Val{:PositiveSemidefiniteConeSquare}, object::Object)
533546
return MOI.PositiveSemidefiniteConeSquare(object["side_dimension"])
534547
end

src/FileFormats/MOF/write.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ head_name(::Type{MOI.ExponentialCone}) = "ExponentialCone"
289289
head_name(::Type{MOI.DualExponentialCone}) = "DualExponentialCone"
290290
head_name(::Type{MOI.NormOneCone}) = "NormOneCone"
291291
head_name(::Type{MOI.NormInfinityCone}) = "NormInfinityCone"
292+
head_name(::Type{MOI.NormCone}) = "NormCone"
292293
head_name(::Type{MOI.RelativeEntropyCone}) = "RelativeEntropyCone"
293294
head_name(::Type{MOI.NormSpectralCone}) = "NormSpectralCone"
294295
head_name(::Type{MOI.NormNuclearCone}) = "NormNuclearCone"
@@ -299,6 +300,9 @@ head_name(::Type{MOI.LogDetConeSquare}) = "LogDetConeSquare"
299300
function head_name(::Type{MOI.PositiveSemidefiniteConeTriangle})
300301
return "PositiveSemidefiniteConeTriangle"
301302
end
303+
function head_name(::Type{MOI.ScaledPositiveSemidefiniteConeTriangle})
304+
return "ScaledPositiveSemidefiniteConeTriangle"
305+
end
302306
function head_name(::Type{MOI.PositiveSemidefiniteConeSquare})
303307
return "PositiveSemidefiniteConeSquare"
304308
end

test/FileFormats/MOF/MOF.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,18 @@ c1: [x1, x2, x3] in PositiveSemidefiniteConeTriangle(2)
770770
)
771771
end
772772

773+
function test_ScaledPositiveSemidefiniteConeTriangle()
774+
return _test_model_equality(
775+
"""
776+
variables: x1, x2, x3
777+
minobjective: x1
778+
c1: [x1, x2, x3] in ScaledPositiveSemidefiniteConeTriangle(2)
779+
""",
780+
["x1", "x2", "x3"],
781+
["c1"],
782+
)
783+
end
784+
773785
function test_PositiveSemidefiniteConeSquare()
774786
return _test_model_equality(
775787
"""
@@ -887,6 +899,18 @@ c1: [x, y] in NormInfinityCone(2)
887899
)
888900
end
889901

902+
function test_NormCone()
903+
return _test_model_equality(
904+
"""
905+
variables: x, y
906+
minobjective: x
907+
c1: [x, y] in NormCone(1.5, 2)
908+
""",
909+
["x", "y"],
910+
["c1"],
911+
)
912+
end
913+
890914
function test_RelativeEntropyCone()
891915
return _test_model_equality(
892916
"""

test/FileFormats/MOF/nlp.mof.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "MathOptFormat Model",
33
"version": {
44
"major": 1,
5-
"minor": 3
5+
"minor": 4
66
},
77
"variables": [
88
{

0 commit comments

Comments
 (0)