Python Python: Semidefinite program with CVXPy 'Error parsing inputs'

  • Thread starter Thread starter Master1022
  • Start date Start date
  • Tags Tags
    Program Python
Click For Summary
The error 'Error parsing inputs' in CVXPy is likely due to compatibility issues between the CVXPy package and the Python 3.7 environment in Google Colab. Users have found that the same code works correctly in a local Jupyter Notebook with Python 3.9, indicating that the problem may stem from version discrepancies. To resolve the issue, users are advised to check the version of CVXPy being used in Google Colab and consider updating their environment or switching to a local setup where the code functions as intended.
Master1022
Messages
590
Reaction score
116
TL;DR
I am trying to run a semidefinite program in Python using CVXPy. I have gone to the documentation and the example code in there doesn't run in Google Colab for me and yields the error: 'Error parsing inputs'.
Hi,

Question:
Why is the error 'Error parsing inputs' in CVXPy occurring?

Context:
I am trying to solve a semidefinite program in CVXPy (using Google Colab). I went to the documentation (HERE) and I copied the example code into a cell. It doesn't work for some reason and I don't understand why. It is throwing the following message: 'Error parsing inputs'. Why is this happening?

Code:
[CODE lang="python" title="CVXPy Semidefinite Code Documentation Example"]# Import packages.
import cvxpy as cp
import numpy as np

# Generate a random SDP.
n = 3
p = 3
np.random.seed(1)
C = np.random.randn(n, n)
A = []
b = []
for i in range(p):
A.append(np.random.randn(n, n))
b.append(np.random.randn())

# Define and solve the CVXPY problem.
# Create a symmetric matrix variable.
X = cp.Variable((n,n), symmetric=True)
# The operator >> denotes matrix inequality.
constraints = [X >> 0]
constraints += [
cp.trace(A @ X) == b for i in range(p)
]
prob = cp.Problem(cp.Minimize(cp.trace(C @ X)),
constraints)
prob.solve()

# Print result.
print("The optimal value is", prob.value)
print("A solution X is")
print(X.value)[/CODE]Any help would be greatly appreciated
 
Technology news on Phys.org
This appears to be a compatibility problem with the cvxpy package and the Google Colab Python 3.7 environment. It works for me in a local Jupyter Notebook environment (Python 3.9).
 
  • Informative
  • Like
Likes Master1022 and berkeman
pbuk said:
This appears to be a compatibility problem with the cvxpy package and the Google Colab Python 3.7 environment. It works for me in a local Jupyter Notebook environment (Python 3.9).
Thanks for the reply @pbuk ! That's correct - when I used a version on my local machine via a conda environment, then it worked
 

Similar threads

Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 28 ·
Replies
28
Views
4K