Conversion to double from cvx is not possible error despite expression holders being used

I am getting ‘conversion to double from Cvx not possible’ error in the line “Rcup_kmn(k,m,n) = Blog2(1 + X/Y)+ ex_diff(1)(c_q(m,n,1,1) - ex_q(1)) + ex_diff(2)*(c_q(m,n,1,2) - ex_q(2));” i used expression holders. Can you help me with what I might be missing?

run(‘init.m’);
cvx_begin
variable c_q(M,N, 1,2);
Rcup_kmn = R_kmn;
for k = 1:K
for m = 1:K
for n = 1:N
D1 = norm(reshape(q(m,n,:,:),[1 2]) -W_k(k,:),2)^2 + H^2;
D2 = norm(reshape(q(m,n,:,:),[1 2]) -W_m,2)^2 + (H - H_m)^2;
X = P_DU(k,m,n) * P_UM(m,n) * h_0/sigma2;
Y = P_DU(k,m,n) * D2 + P_UM(m,n)D1;
diff = -1
(BX /(log(2)(Y+X)Y)) * (P_DU(k,m,n) (reshape(q(m,n,:,:),[1 2]) -W_m ) - P_UM(m,n)(reshape(q(m,n,:,:),[1 2])- W_k(k,:)));
expression ex_diff(2);
ex_diff(1) = diff(1,1);ex_diff(2) = diff(1,2);
expression ex_q(1,2);
ex_q(1) = q(m,n,1,1); ex_q(2) = q(m,n,1,2);
Rcup_kmn(k,m,n) = B
log2(1 + X/Y)+ ex_diff(1)(c_q(m,n,1,1) - ex_q(1)) + ex_diff(2)(c_q(m,n,1,2) - ex_q(2));
end
end
end

Rcup = (1/N) * sum(a.*Rcup_kmn, 3);
aR =  a .* Rcup;   
LO = L_k .* (1+O_k);
        expression temp_E;
    ds_h = delta*sigma2/h_0;
    for k = 1:K
        for m = 1:M
            for n = 1:N
                temp_E = temp_E + a(k,m,n)*ds_h*(H^2 + pow_pos(norm(reshape(c_q(m,n,:,:),[1 2]) -W_k(k,:),2),2))*(w_1*(2^(l_DU(k,m,n)/(delta*B_DU(k,m,n)))-1) + w_2*(2^(l_UK(k,m,n)/(delta*B_UK(k,m,n)))-1)) + w_2*ds_h*((H-H_m)^2 + pow_pos(norm(reshape(c_q(m,n,:,:),[1 2]) - W_m,2),2))*(2^(l_UM(k,m,n)/(delta*B_UM(k,m,n)))-1);
            end
        end
    end
    
      for m = M
          for n = N-1
              temp_E = temp_E + w_2*0.5*Q*Delta*(norm(reshape(c_q(m,n+1,:,:),[1 2])-reshape(c_q(m,n,:,:),[1 2])))^2;
          end
      end
minimize temp_E  - zeta*(sum(Rcup_kmn(:))/N);  

for m = 1:M
    c_q(m,1,:,:) == c_q(m,N,:,:); %C6
end
for m = 1:M
    for n = 1:N-1
        norm(c_q(m,n+1,:,:) - c_q(m,n,:,:))^2 <= S_max^2; %C7
    end
end
a .* dist2 <= H *sqrt(3); %C8
sum(LO) <= sum(aR(:)) <= C_max;%C10 
for n = 1:N
    for m = 1:M
        for j = m+1:M
            - norm(reshape(q(m,n,:,:),[1 2])-reshape(q(j,n,:,:),[1 2]))^2 +  2*(reshape(q(m,n,:,:),[1 2])-reshape(q(j,n,:,:),[1 2])) * transpose(reshape(c_q(m,n,:,:),[1 2])-reshape(c_q(j,n,:,:),[1 2])) >= d_min^2;
        end
    end
end
0 <= a <= 1; %C21

cvx_end

q = c_q;

Because you have not supplied the input data to make this reproducible, perhaps you can tell us exactly where the error occurred and show us the CVX error message.

Below is the initialization of parameters:

B = 30e+6; % Bandwidth
T = 10; % Time process
N = 20; % The number of time slots
K = 6 ; % The number of IoRT devices
M = 3 ; % The number of UAVs
radius = 300;
sigma2 = 3.9810717055e-10 ; % Noise power -60dBm = 3.9810717055e-10 W
h_0 = db2pow(-30); % The channel gain at a reference distance of 1m
H = 10; % The fixed height of the UAVs
H_m = 20; % The height of MEC device (antenna)
d_min = 100; % The minimum safety distance among different UAVs
V_max = 10; % The maximum speed of UAV 10m/s xhu
Q = 9.65; % The mass of UAV 9.65kg
w_1 = 0.2; % The weight for the energy consumption of the UAVs 0.5
w_2 = 0.8; % The weight for the energy consumption of The IoRT devices 1
P_max_Iort = 1; % The maximum transmission power of IoRT devices 1W
P_max_UAV = 50 ; % The maximum transmission power of the UAVs 50W
C_max = 100e+9; % The maximum capacity of MEC device C_{max} 100Mbps
L_k = [50 100 150 200 250 300]’ .* 1e6; % The task-input size of IoRT device 50 Mb - 300 Mb
O_k = zeros(K,1) + 0.8; % IoRT device’s task size ratio of output data to input data O_{k} (k\in \mathcal{K}) 30MHz
epsilon = 1e-4; % The error tolerance threshold \epsilon 10^{-4} xhu
W_k = [-200 -200; -200 200; 200 -200; 200 200; 150 -150; -150 150]; % Locations of IoRT devices | different in xhu
W_m = [0 0]; % Location of MEC
zeta = 1; % penalty term

cottheta = cotd(30);

Delta = T/N; % Length of time slot
q = zeros(M,N, 1,2); % trajectorty given by q_mn
P_DU = zeros(K,M,N); % uplink transmission power - device to UAV
h_DU = zeros(K,M,N); % uplink transmission power - device to UAV
gamma_DU = zeros(K,M,N); % SNR - device to UAV
P_UM = zeros(M,N); % uplink transmission power - UAV to MEC
h_UM = zeros(M,N); % uplink transmission power - UAV to MEC
gamma_UM = zeros(M,N); % SNR - UAV to MEC
R_kmn = zeros(K,M,N); % uplink transmission rate
a = zeros(K,M,N); % connection scheduling
delta = Delta / K;
E_DU = zeros(K,M,N); % energy to transmit - device to UAV
E_UM = zeros(K,M,N); % energy to transmit - UAV to MEC
E_UK = zeros(K,M,N); % energy to transmit - UAV to device
B_DU = zeros(K,M,N); % bandwidth - device to UAV
B_UM = zeros(K,M,N); % bandwidth - UAV to MEC
B_UK = zeros(K,M,N); % bandwidth - UAV to device
l_DU = zeros(K,M,N); % bits - device to UAV l_km
l_UM = zeros(K,M,N); % bits - UAV to MEC l_km_off
l_UK = zeros(K,M,N); % bits - UAV to device l_km_down
v = zeros(M,N); % velocity
E_f = zeros(M,N); % energy to fly

% Trajectory initialization
R = radius/2;

theta=linspace(0,360,M+1); theta(end)=[];
i_x=Rcosd(theta)+W_m(1); %centers
i_y=R
sind(theta)+W_m(2); %centers

for m = 1:M

R =  norm([i_x(1) - i_x(2)  i_y(1) - i_y(2)])/2 - H*cottheta;

theta=linspace(0,360,N+1); theta(end)=[];
i_x1=R*cosd(theta)+i_x(m);
i_y1=R*sind(theta)+i_y(m);
for n = 1:N
    q(m,n,1,1) = i_x1(n);
    q(m,n,1,2) = i_y1(n);
end  

end

S_max = V_max * Delta;
% Power levels initialization
P_DU = P_DU + P_max_Iort; % uplink transmission power - device to UAV

P_UM = P_UM + P_max_UAV; % uplink transmission power - UAV to MEC

% initialization of bandwidth and bit allocations
for k = 1:K
for m = 1:M
for n = 1:N
temp = L_k(k)/(M*(N-2));
l_DU(k,m,n) = temp;
l_UM(k,m,n) = temp;
l_UK(k,m,n) = O_k(k)temp;
den = 3
KM(N-2);
B_DU(k,m,n) = B/den;
B_UM(k,m,n) = B/den;
B_UK(k,m,n) = O_k(k)*B/den;
if(n==1)
l_UM(k,m,n) = 0;
l_UK(k,m,n) = 0;
end
if(n==2)
l_UK(k,m,n) = 0;
end
if(n==N-1)
l_DU(k,m,n) = 0;
end
if(n==N)
l_DU(k,m,n) = 0;
l_UM(k,m,n) = 0;
end

    end
end

end

‘db2pow’ requires Signal Processing Toolbox.

In any event, maybe you could do some more investigation, see which line triggers the error, then try to simplify as much as possible to isolate the error.

error is from this line:

“Rcup_kmn(k,m,n) = Blog2(1 + X/Y)+ ex_diff(1)(c_q(m,n,1,1) - ex_q(1)) + ex_diff(2)*(c_q(m,n,1,2) - ex_q(2))" … line 17 in the code of first post

You didn’t use an expression holder for Rcup_kmn . Instead, you have the statement, Rcup_kmn = R_kmn;, where `R_kmn’ is a double precision (MATLAB) variable. Hence the error.

1 Like

Oops… Thanks for the help.

Mark,

I get another error:Disciplined convex programming error:
Cannot perform the operation: {zero} .* {positive constant}

in the line 31 of code in first post, calculation of temp_E

The line “temp_E = temp_E + a(k,m,n)*ds_h*(H^2 + pow_pos(norm(reshape(c_q(m,n,:,:),[1 2]) -W_k(k,:),2....

I actually changed the values of matrix a to non-zero… I dont see any other parameter becoming zero… I could not understand what is the issue.

Can you kindly help with this?

I don’t think I’ve ever seen that error before.

Type each “thing” in the command line and see what it says.

Do you get the same error if instead of
expression temp_E;
you have
temp_E = 0;

I think those two should be equivalent, though. (You don’t need expression holder or to declare expression) when expression is a scalar). By default, all declared expressions are initialized to zero.

Edit: I just corrected a typo to remove “don’t” from “I don’t think”.

Try to find out what the {positive constant} is and what the {zero} is.

I don’t know under what circumstances CVX would characterize something as those without their interacting with a CVX expression , If everything is constant, then what business is it of CVX’s, i.e. ,why a CVX error message involving those?

Actually some values of the matrix ‘a’ were zeros and it gave above error… I fixed that by making all values in matrix ‘a’ non-zero…
Now I see this:

Disciplined convex programming error:
Cannot perform the operation: {convex} .* {positive constant}

This might be the underlying error even before…

I am multiplying convex expression with a constant.It is not .* as in the error . I wonder what’s the issue.

I don’t know. I suggest trying to progressively simplify things to see when the error (dis)appears

1 Like

:smiley: Thanks for the help

There’s an awful lot of stuff going on in that single line of code. Find the piece(es) causing the error.

One thing which does come to mind is that CVX is good about reporting an error when there is a DCP violation, but it is not very good at making sure the error message is indicative of what the true error is. So maybe you have an actual DCP error for which a “nonsensical” error message is issued.

1 Like

Hi Mark,

Could you kindly decode the below error for me? I have no clue about what is this:

Calling SDPT3 4.0: 6053 variables, 2971 equality constraints

num. of constraints = 2971
dim. of sdp var = 1484, num. of sdp blk = 742
dim. of socp var = 2226, num. of socp blk = 742
dim. of linear var = 1601


SDPT3: Infeasible path-following algorithms


version predcorr gam expon scale_data
HKM 1 0.000 1 0
it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime

0|0.000|0.000|1.4e+02|1.0e+00|2.7e+18| 1.362476e+18 0.000000e+00| 0:0:01|
spchol 1
2
1|0.000|0.000|1.4e+02|1.0e+00|2.7e+18| 1.362476e+18 2.904258e+07| 0:0:02| spchol 1 2

2|0.000|0.000|1.4e+02|1.0e+00|2.7e+18| 1.362475e+18 -3.319193e+07| 0:0:02| spchol 1 2
3|0.000|0.000|1.4e+02|1.0e+00|2.7e+18| 1.362473e+18 1.248971e+07| 0:0:02| spchol 1 2
4|0.000|0.000|1.4e+02|1.0e+00|2.7e+18| 1.362403e+18 -1.179756e+09| 0:0:02|
*** Too many tiny steps: restarting with the following iterate.
*** [X,y,Z] = infeaspt(blk,At,C,b,2,1e5);
spchol 1 1
5|0.000|0.000|1.5e+01|1.0e+00|3.7e+20| 1.560898e+25 -7.911557e+03| 0:0:02|
*** Too many tiny steps even after restarting
stop: steps too short consecutively*

number of iterations = 5
primal objective value = 1.56089763e+25
dual objective value = -7.91155661e+03
gap := trace(XZ) = 3.73e+20
relative gap = 2.39e-05
actual relative gap = 1.00e+00
rel. primal infeas (scaled problem) = 1.47e+01
rel. dual " " " = 1.00e+00
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual " " " = 0.00e+00
norm(X), norm(y), norm(Z) = 9.4e+12, 5.2e+06, 4.5e+07
norm(A), norm(b), norm© = 5.7e+03, 6.0e+05, 1.8e+12
Total CPU time (secs) = 2.34
CPU time per iteration = 0.47
termination code = -5
DIMACS: 1.1e+02 0.0e+00 1.8e+00 0.0e+00 1.0e+00 2.4e-05


Status: Failed
Optimal value (cvx_optval): NaN

The solver had numerical difficulty. Based on the solver output and a quick perusal of some of the input data, it appears that the input data is too extreme for the solver to handle. Try scaling (choosing units) so that non-zero numbers are within a small number of orders of magnitude of 1.

A more robust solver, such as Mosek, which also provides more diagnostic output, might help. But better scaling is very likely needed in any event.

1 Like

Hi,

I am implementing Successive convex Approximation.

The inner loop runs fine in the first iteration but throws the below error in the second iteration:

Disciplined convex programming error:
Illegal operation: {real affine} - {invalid}

Error in - (line 21)
z = plus( x, y, true, cheat );

Error in sub2 (line 17)
phitilde1 = log2(psi) + (1./(log(2) .* psi)) .* (h_DU .* exp(alpha_r)) .* (c_alpha - alpha_r) + h_DU .* h_kUM .* exp(alpha_r + beta_r) .* ((c_alpha - alpha_r) + (c_kbeta-beta_r)) + h_kUM .*
exp(beta_r) .* (c_kbeta - beta_r);

Dont understand how it goes through the first time but not the second

When the solver fails due to numerical difficulties or infeasibility, the values of the optimization variables are NaN. When you use these values in the next iteration, they are NaN, which results in invalid CVX expression(s).

You can see my thoughts on SCA by reading some of my recent posts on it. if you use SCA, you’re on your own.