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

  • Thread starter Thread starter Master1022
  • Start date Start date
  • Tags Tags
    Program Python
AI Thread 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 Summary
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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top