With Mathematica 12.2, ConvexOptimization was introduced, which, as its name suggests, can solve arbitrary convex optimization problems over matrices [Language Reference]. Using ConvexOptimization can help me get around reformulating my problem into SemidefiniteOptimization, a step that is cumbersome but otherwise works fine.

Hence, to get started, I'm attempting to solve a trial optimization problem with ConvexOptimization.

The following code works as intended.

A = RandomVariate[NormalDistribution[], {4, 4}]
ConvexOptimization[-Log[Det[A.X.Transpose[A]]], {Tr[X] <= 1, VectorGreaterEqual[{X,  0}, {"SemidefiniteCone", 4}]}, {X \[Element] Matrices[{4, 4}, Complexes]}]

However, when I replace the objective function -Log[Det[A.X.Transpose[A]]] with -Log[Det[IdentityMatrix[4] + A.X.Transpose[A]]] to obtain the following optimization problem:

A = RandomVariate[NormalDistribution[], {4, 4}]
ConvexOptimization[-Log[Det[IdentityMatrix[4] + A.X.Transpose[A]]], {Tr[X] <= 1, VectorGreaterEqual[{X,  0}, {"SemidefiniteCone", 4}]}, {X \[Element] Matrices[{4, 4}, Complexes]}]

and evaluate it, Mathematica produces the following error: The argument [...] should not be scalar valued.

I interpret the resulting stack trace on my PC to mean that Mathematica is likely (erroneously) considering the argument to Det a scalar. However, I'm stuck with debugging here.

Would anyone know what might be going wrong? Any suggestions for solving the second optimization problem with ConvexOptimization will be very helpful.


1 Answer 1


(Too long for a comment)

The basic issue is that evaluating Plus does automatic threading when given an explicit matrix (for example, IdentityMatrix[4] + expr).

One way to work around the threading behavior for this particular case would be something like

A = RandomVariate[NormalDistribution[], {4, 4}];

ConvexOptimization[-Log[Det[B + A . X . Transpose[A]]], 
    {Tr[X] <= 1, VectorGreaterEqual[{X, 0}, {"SemidefiniteCone", 4}],
     B == IdentityMatrix[4]}, 
    {X \[Element] Matrices[{4, 4}, Complexes], B \[Element] Matrices[{4, 4}]}]

The above will work in the currently released versions. In a future release, it will be possible to take the more general approach of using Inactive[Plus], that is

   -Log[Det[Inactive[Plus][IdentityMatrix[4], A . X . Transpose[A]]]], ...}
  • 1
    $\begingroup$ It's too bad Inactive[Plus][IdentityMatrix[4], -Log[Det[B + A . X . Transpose[A]]]] didn't work. $\endgroup$
    – Carl Woll
    Oct 21, 2021 at 19:12
  • 1
    $\begingroup$ Right, I think this may be improved. $\endgroup$
    – ilian
    Oct 21, 2021 at 19:23
  • 1
    $\begingroup$ Thank you for the explanation; the provided workaround solves the posted problem. I will update this Q&A once this problem is completely resolved by Mathematica. $\endgroup$ Oct 22, 2021 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.