Skip to content

Commit 73e6a99

Browse files
committed
Document package extension in README.md
1 parent d06ab54 commit 73e6a99

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,35 @@ model_2 = Model(() -> KNITRO.Optimizer(; license_manager = manager))
6767

6868
To release the license manager, do `KNITRO.KN_release_license(manager)`.
6969

70+
### Type stability
71+
72+
KNITRO.jl v0.14.7 moved the `KNITRO.Optimizer` object to a package extension. As
73+
a consequence, `KNITRO.Optimizer` is now type unstable, and it will be inferred
74+
as `KNITRO.Optimizer()::Any`.
75+
76+
In most cases, this should not impact performance. If it does, there are two
77+
work-arounds.
78+
79+
First, you can use a function barrier:
80+
```julia
81+
using JuMP, KNITRO
82+
function main(optimizer::T) where {T}
83+
model = Model(optimizer)
84+
return
85+
end
86+
main(KNITRO.Optimizer)
87+
```
88+
Although the outer `KNITRO.Optimizer` is type unstable, the `optimizer` inside
89+
`main` will be properly inferred.
90+
91+
Second, you may explicitly get and use the extension module:
92+
```julia
93+
using JuMP, KNITRO
94+
const KNITROMathOptInterfaceExt =
95+
Base.get_extension(KNITRO, :KNITROMathOptInterfaceExt)
96+
model = Model(KNITROMathOptInterfaceExt.Optimizer)
97+
```
98+
7099
## Use with AMPL
71100

72101
To use KNITRO with [AmplNLWriter.jl](https://github.com/jump-dev/AmplNLWriter.jl),

0 commit comments

Comments
 (0)