Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Wrong number or type of arguments for overloaded function 'IntIntMap___setitem__'. #2446

Open
LP123MYM opened this issue May 15, 2024 · 4 comments

Comments

@LP123MYM
Copy link

Describe the bug

The following error occurred when I ran the code for a long time

pgon = o.set.polygon()

File "/home/mym/code_GPU/src/sets/Polytope.py", line 107, in polygon
V = self.vertices()
File "/home/mym/code_GPU/src/sets/Polytope.py", line 47, in vertices
return self.vertices2D()
File "/home/mym/code_GPU/src/sets/Polytope.py", line 59, in vertices2D
p = self.center()
File "/home/mym/code_GPU/src/sets/Polytope.py", line 91, in center
prob.solve(solver="ECOS")
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 495, in solve
return solve_func(self, *args, **kwargs)
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 1057, in solve
solver, gp, enforce_dpp, ignore_dpp, verbose, canon_backend, kwargs
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 683, in get_problem_data
data, inverse_data = solving_chain.apply(self, verbose)
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/chain.py", line 76, in apply
problem, inv = r.apply(problem)
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/dcp2cone/cone_matrix_stuffing.py", line 336, in apply
problem, extractor)
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/dcp2cone/cone_matrix_stuffing.py", line 327, in stuffed_objective
params_to_c = extractor.affine(problem.objective.expr)
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/utilities/coeff_extractor.py", line 92, in affine
self.canon_backend)
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/cvxcore/python/canonInterface.py", line 325, in get_problem_matrix
id_to_col_C[int(id)] = int(col)
File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/cvxcore/python/cvxcore.py", line 738, in setitem
return cvxcore.IntIntMap___setitem
(self, *args)
TypeError: Wrong number or type of arguments for overloaded function 'IntIntMap___setitem__'.
Possible C/C++ prototypes are:
std::map< int,int >::setitem(std::map< int,int >::key_type const &)
std::map< int,int >::setitem(std::map< int,int >::key_type const &,std::map< int,int >::mapped_type const &)

p = self.center()
def center(self):
"""compute Chebychev center of a polytope"""

    tmp = np.expand_dims(np.linalg.norm(self.c, axis=1), axis=1)
    c = np.concatenate((self.c, tmp), axis=1)
    cost = np.zeros(self.c.shape[1] + 1)
    cost[-1] = -1.

    x = cp.Variable((len(cost), 1))
    prob = cp.Problem(cp.Minimize(np.expand_dims(cost, axis=0) @ x), [c @ x <= self.d])
    prob.solve(solver="ECOS")
    # solve with another solver for optimal_inaccurate
    if prob.status != "optimal":
        prob.solve(solver="MOSEK")

    assert prob.status == "optimal", f"id={self.id}, status={prob.status}"
    p = x.value[:-1]

    if not np.all(np.dot(self.c, p) <= self.d):
        raise Exception('Computation of the Chebychev center failed!')

    return p

Version

  • OS: ubuntu18.04
  • CVXPY Version:1.3.1
@rileyjmurray
Copy link
Collaborator

rileyjmurray commented May 15, 2024 via email

@LP123MYM
Copy link
Author

Hi! Can you run with python 3.8 and CVXPY 1.4 or higher? Python 3.7 is no longer supported by the Python Software Foundation, and we no longer support CVXPY 1.3 (following the recent release of 1.5).

On Wed, May 15, 2024 at 4:59 AM LP123MYM @.***> wrote: Describe the bug The following error occurred when I ran the code for a long time pgon = o.set.polygon() File "/home/mym/code_GPU/src/sets/Polytope.py", line 107, in polygon V = self.vertices() File "/home/mym/code_GPU/src/sets/Polytope.py", line 47, in vertices return self.vertices2D() File "/home/mym/code_GPU/src/sets/Polytope.py", line 59, in vertices2D p = self.center() File "/home/mym/code_GPU/src/sets/Polytope.py", line 91, in center prob.solve(solver="ECOS") File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 495, in solve return solve_func(self, *args, kwargs) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 1057, in solve solver, gp, enforce_dpp, ignore_dpp, verbose, canon_backend, kwargs File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 683, in get_problem_data data, inverse_data = solving_chain.apply(self, verbose) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/chain.py", line 76, in apply problem, inv = r.apply(problem) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/dcp2cone/cone_matrix_stuffing.py", line 336, in apply problem, extractor) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/dcp2cone/cone_matrix_stuffing.py", line 327, in stuffed_objective params_to_c = extractor.affine(problem.objective.expr) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/utilities/coeff_extractor.py", line 92, in affine self.canon_backend) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/cvxcore/python/canonInterface.py", line 325, in get_problem_matrix id_to_col_C[int(id)] = int(col) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/cvxcore/python/cvxcore.py", line 738, in setitem return cvxcore.IntIntMap___setitem(self, args) TypeError: Wrong number or type of arguments for overloaded function 'IntIntMap___setitem__'. Possible C/C++ prototypes are: std::map< int,int >::setitem(std::map< int,int >::key_type const &) std::map< int,int >::setitem(std::map< int,int >::key_type const &,std::map< int,int >::mapped_type const &) p = self.center() def center(self): """compute Chebychev center of a polytope""" tmp = np.expand_dims(np.linalg.norm(self.c, axis=1), axis=1) c = np.concatenate((self.c, tmp), axis=1) cost = np.zeros(self.c.shape[1] + 1) cost[-1] = -1. x = cp.Variable((len(cost), 1)) prob = cp.Problem(cp.Minimize(np.expand_dims(cost, axis=0) @ x), [c @ x <= self.d]) prob.solve(solver="ECOS") # solve with another solver for optimal_inaccurate if prob.status != "optimal": prob.solve(solver="MOSEK") assert prob.status == "optimal", f"id={self.id}, status={prob.status}" p = x.value[:-1] if not np.all(np.dot(self.c, p) <= self.d): raise Exception('Computation of the Chebychev center failed!') return p Version - OS: ubuntu18.04 - CVXPY Version:1.3.1 — Reply to this email directly, view it on GitHub <#2446>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACRLIFFAONFX3Y5FMOITOGDZCMPWHAVCNFSM6AAAAABHXW4O2OVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI4TOMRXGYYDKMQ . You are receiving this because you are subscribed to this thread.Message ID: @.>

Thank you for your reply. I will try using Python 3.8

@LP123MYM
Copy link
Author

LP123MYM commented May 19, 2024

I tried Python=3.8.1 and cvxpy=1.5.1, but still reported the above error。I ran it for about two days and reported an error,Below is the minimum error example:

import numpy as np
import cvxpy as cp
temp_lr = 1.0/15/8.0
num_rep = 50
T = 10**6
s_t = 0
cum_loss_est = np.array([0.0, 1.0,2.0,3.0,4.0,5.0,6.0,7.0])
for run in range(num_rep):
    for t in range(T):
        w = cp.Variable(8, pos=True)
        obj = cp.Minimize(temp_lr * (cum_loss_est.T  @ w)  - cp.sum(cp.entr(w)) - (2*temp_lr) * cp.sum(cp.log(w)) )
        cons = [cp.sum(w)==1]
        prob = cp.Problem(obj,cons)
        prob.solve(solver='ECOS')
        s_t  += 1
        print("s_t ",s_t)

@LP123MYM
Copy link
Author

Hi! Can you run with python 3.8 and CVXPY 1.4 or higher? Python 3.7 is no longer supported by the Python Software Foundation, and we no longer support CVXPY 1.3 (following the recent release of 1.5).

On Wed, May 15, 2024 at 4:59 AM LP123MYM @.***> wrote: Describe the bug The following error occurred when I ran the code for a long time pgon = o.set.polygon() File "/home/mym/code_GPU/src/sets/Polytope.py", line 107, in polygon V = self.vertices() File "/home/mym/code_GPU/src/sets/Polytope.py", line 47, in vertices return self.vertices2D() File "/home/mym/code_GPU/src/sets/Polytope.py", line 59, in vertices2D p = self.center() File "/home/mym/code_GPU/src/sets/Polytope.py", line 91, in center prob.solve(solver="ECOS") File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 495, in solve return solve_func(self, *args, kwargs) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 1057, in solve solver, gp, enforce_dpp, ignore_dpp, verbose, canon_backend, kwargs File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 683, in get_problem_data data, inverse_data = solving_chain.apply(self, verbose) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/chain.py", line 76, in apply problem, inv = r.apply(problem) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/dcp2cone/cone_matrix_stuffing.py", line 336, in apply problem, extractor) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/reductions/dcp2cone/cone_matrix_stuffing.py", line 327, in stuffed_objective params_to_c = extractor.affine(problem.objective.expr) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/utilities/coeff_extractor.py", line 92, in affine self.canon_backend) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/cvxcore/python/canonInterface.py", line 325, in get_problem_matrix id_to_col_C[int(id)] = int(col) File "/home/mym/anaconda3/envs/safe_rl_gpu/lib/python3.7/site-packages/cvxpy/cvxcore/python/cvxcore.py", line 738, in setitem return cvxcore.IntIntMap___setitem(self, args) TypeError: Wrong number or type of arguments for overloaded function 'IntIntMap___setitem__'. Possible C/C++ prototypes are: std::map< int,int >::setitem(std::map< int,int >::key_type const &) std::map< int,int >::setitem(std::map< int,int >::key_type const &,std::map< int,int >::mapped_type const &) p = self.center() def center(self): """compute Chebychev center of a polytope""" tmp = np.expand_dims(np.linalg.norm(self.c, axis=1), axis=1) c = np.concatenate((self.c, tmp), axis=1) cost = np.zeros(self.c.shape[1] + 1) cost[-1] = -1. x = cp.Variable((len(cost), 1)) prob = cp.Problem(cp.Minimize(np.expand_dims(cost, axis=0) @ x), [c @ x <= self.d]) prob.solve(solver="ECOS") # solve with another solver for optimal_inaccurate if prob.status != "optimal": prob.solve(solver="MOSEK") assert prob.status == "optimal", f"id={self.id}, status={prob.status}" p = x.value[:-1] if not np.all(np.dot(self.c, p) <= self.d): raise Exception('Computation of the Chebychev center failed!') return p Version - OS: ubuntu18.04 - CVXPY Version:1.3.1 — Reply to this email directly, view it on GitHub <#2446>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACRLIFFAONFX3Y5FMOITOGDZCMPWHAVCNFSM6AAAAABHXW4O2OVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI4TOMRXGYYDKMQ . You are receiving this because you are subscribed to this thread.Message ID: @.>

The minimum number of running steps for error reporting is 28633115 steps in version 1.5.1, 30678338 steps in version 1.3.1, and 30678338 steps in version 1.2.1. The number of running steps referred to here is s_t in the minimum example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants