Skip to content

Commit

Permalink
Doctest fixes for complex printing update
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Apr 27, 2023
1 parent ec26e03 commit f700351
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
24 changes: 12 additions & 12 deletions docs/src/manual/complex.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Create a complex-valued variable using [`ComplexPlane`](@ref):
julia> model = Model();
julia> @variable(model, x in ComplexPlane())
real(x) + (0.0 + 1.0im) imag(x)
real(x) + im imag(x)
```

Note that `x` is not a [`VariableRef`](@ref); instead, it is an affine
Expand Down Expand Up @@ -64,7 +64,7 @@ To create an anonymous variable, use the `set` keyword argument:
julia> model = Model();
julia> x = @variable(model, set = ComplexPlane())
_[1] + (0.0 + 1.0im) _[2]
_[1] + im _[2]
```

## Complex-valued variable bounds
Expand All @@ -85,7 +85,7 @@ julia> @variable(
upper_bound = 2.0 + 3.0im,
start = 4im,
)
real(x) + (0.0 + 1.0im) imag(x)
real(x) + im imag(x)
julia> vars = all_variables(model)
2-element Vector{VariableRef}:
Expand Down Expand Up @@ -125,7 +125,7 @@ julia> set_silent(model)
julia> @variable(model, x[1:2]);
julia> @constraint(model, (1 + 2im) * x[1] + 3 * x[2] == 4 + 5im)
(1.0 + 2.0im) x[1] + (3.0 + 0.0im) x[2] = 4.0 + 5.0im
(1 + 2im) x[1] + 3 x[2] = 4.0 + 5.0im
julia> optimize!(model)
Expand Down Expand Up @@ -168,7 +168,7 @@ julia> set_silent(model)
julia> @variable(model, x in ComplexPlane());
julia> @constraint(model, (1 + 2im) * x + 3 * x == 4 + 5im)
(4.0 + 2.0im) real(x) + (-2.0 + 4.0im) imag(x) = 4.0 + 5.0im
(4 + 2im) real(x) + (-2 + 4im) imag(x) = 4.0 + 5.0im
julia> optimize!(model)
Expand Down Expand Up @@ -207,9 +207,9 @@ julia> model = Model();
julia> @variable(model, H[1:3, 1:3] in HermitianPSDCone())
3×3 LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
real(H[1,1]) … real(H[1,3]) + (0.0 + 1.0im) imag(H[1,3])
real(H[1,2]) + (0.0 - 1.0im) imag(H[1,2]) real(H[2,3]) + (0.0 + 1.0im) imag(H[2,3])
real(H[1,3]) + (0.0 - 1.0im) imag(H[1,3]) real(H[3,3])
real(H[1,1]) … real(H[1,3]) + im imag(H[1,3])
real(H[1,2]) - im imag(H[1,2]) real(H[2,3]) + im imag(H[2,3])
real(H[1,3]) - im imag(H[1,3]) real(H[3,3])
```

Behind the scenes, JuMP has created nine real-valued decision variables:
Expand Down Expand Up @@ -267,12 +267,12 @@ julia> import LinearAlgebra
julia> H = LinearAlgebra.Hermitian([x[1] 1im; -1im -x[2]])
2×2 LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
x[1] (0.0 + 1.0im)
(0.0 - 1.0im) (-1.0 - 0.0im) x[2]
x[1] im
-im -x[2]
julia> @constraint(model, H in HermitianPSDCone())
[x[1] (0.0 + 1.0im);
(0.0 - 1.0im) (-1.0 - 0.0im) x[2]] ∈ HermitianPSDCone()
[x[1] im;
-im -x[2]] ∈ HermitianPSDCone()
```

!!! note
Expand Down
12 changes: 6 additions & 6 deletions docs/src/manual/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ julia> model = Model();
julia> @variable(model, X[1:2, 1:2] in HermitianPSDCone())
2×2 Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
real(X[1,1]) real(X[1,2]) + (0.0 + 1.0im) imag(X[1,2])
real(X[1,2]) + (0.0 - 1.0im) imag(X[1,2]) real(X[2,2])
real(X[1,1]) real(X[1,2]) + im imag(X[1,2])
real(X[1,2]) - im imag(X[1,2]) real(X[2,2])
julia> @constraint(model, X == LinearAlgebra.I)
[real(X[1,1]) + (-1.0 - 0.0im) real(X[1,2]) + (0.0 + 1.0im) imag(X[1,2]);
real(X[1,2]) + (0.0 - 1.0im) imag(X[1,2]) real(X[2,2]) + (-1.0 - 0.0im)] ∈ Zeros()
[real(X[1,1]) - 1 real(X[1,2]) + im imag(X[1,2]);
real(X[1,2]) - im imag(X[1,2]) real(X[2,2]) - 1] ∈ Zeros()
julia> @constraint(model, X .== LinearAlgebra.I)
2×2 Matrix{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{ComplexF64}, MathOptInterface.EqualTo{ComplexF64}}, ScalarShape}}:
real(X[1,1]) = 1.0 - 0.0im … real(X[1,2]) + (0.0 + 1.0im) imag(X[1,2]) = 0.0 - 0.0im
real(X[1,2]) + (0.0 - 1.0im) imag(X[1,2]) = 0.0 + 0.0im real(X[2,2]) = 1.0 - 0.0im
real(X[1,1]) = 1.0 - 0.0im … real(X[1,2]) + im imag(X[1,2]) = 0.0 - 0.0im
real(X[1,2]) - im imag(X[1,2]) = 0.0 + 0.0im real(X[2,2]) = 1.0 - 0.0im
```

## Containers of constraints
Expand Down
12 changes: 6 additions & 6 deletions docs/src/manual/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,8 @@ julia> model = Model();
julia> @variable(model, H[1:2, 1:2] in HermitianPSDCone())
2×2 LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
real(H[1,1]) real(H[1,2]) + (0.0 + 1.0im) imag(H[1,2])
real(H[1,2]) + (0.0 - 1.0im) imag(H[1,2]) real(H[2,2])
real(H[1,1]) real(H[1,2]) + im imag(H[1,2])
real(H[1,2]) - im imag(H[1,2]) real(H[2,2])
```

This adds 4 real variables in the [`MOI.HermitianPositiveSemidefiniteConeTriangle`](@ref):
Expand All @@ -1266,8 +1266,8 @@ julia> model = Model();
julia> @variable(model, x[1:2, 1:2], Hermitian)
2×2 LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
real(x[1,1]) real(x[1,2]) + (0.0 + 1.0im) imag(x[1,2])
real(x[1,2]) + (0.0 - 1.0im) imag(x[1,2]) real(x[2,2])
real(x[1,1]) real(x[1,2]) + im imag(x[1,2])
real(x[1,2]) - im imag(x[1,2]) real(x[2,2])
```

This is equivalent to declaring the variable in [`HermitianMatrixSpace`](@ref):
Expand All @@ -1276,8 +1276,8 @@ julia> model = Model();
julia> @variable(model, x[1:2, 1:2] in HermitianMatrixSpace())
2×2 LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
real(x[1,1]) real(x[1,2]) + (0.0 + 1.0im) imag(x[1,2])
real(x[1,2]) + (0.0 - 1.0im) imag(x[1,2]) real(x[2,2])
real(x[1,1]) real(x[1,2]) + im imag(x[1,2])
real(x[1,2]) - im imag(x[1,2]) real(x[2,2])
```

### Why use variables constrained on creation?
Expand Down
4 changes: 0 additions & 4 deletions test/test_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1471,11 +1471,7 @@ function test_extension_HermitianPSDCone_errors(
model = ModelType()
@variable(model, x)
@variable(model, y)
<<<<<<< HEAD
aff_str = "$(GenericAffExpr{ComplexF64,VariableRefType})"
=======
aff_str = "$AffExprType"
>>>>>>> 20919d4a (Improve printing of complex numbers)
err = ErrorException(
"In `@constraint(model, H in HermitianPSDCone(), unknown_kw = 1)`:" *
" Unrecognized constraint building format. Tried to invoke " *
Expand Down

0 comments on commit f700351

Please sign in to comment.