Python: Semidefinite program with CVXPy 'Error parsing inputs'

  • Context: Python 
  • Thread starter Thread starter Master1022
  • Start date Start date
  • Tags Tags
    Program Python
Click For Summary
SUMMARY

The error 'Error parsing inputs' in CVXPy occurs due to compatibility issues between the CVXPy package and the Google Colab Python 3.7 environment. Users have successfully executed the same code in a local Jupyter Notebook environment using Python 3.9, indicating that upgrading the Python version resolves the issue. The problem arises specifically when attempting to solve semidefinite programs with CVXPy in environments that do not support the required features.

PREREQUISITES
  • Familiarity with CVXPy 1.1.15 for convex optimization
  • Understanding of semidefinite programming (SDP)
  • Basic knowledge of Python programming and NumPy
  • Experience with Jupyter Notebook and Google Colab environments
NEXT STEPS
  • Upgrade to Python 3.9 or later in Google Colab for compatibility with CVXPy
  • Explore CVXPy documentation for advanced semidefinite programming examples
  • Learn about matrix inequalities and their applications in optimization
  • Investigate the differences between CVXPy versions and their impact on functionality
USEFUL FOR

Data scientists, optimization researchers, and developers working with convex optimization problems in Python, particularly those using CVXPy in cloud-based environments like Google Colab.

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   Reactions: 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
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · 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 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 28 ·
Replies
28
Views
4K