Skip to content

Commit

Permalink
Address cvxpy vec order warnings
Browse files Browse the repository at this point in the history
cvxpy's vec() function will change the order in which it unravels
matrices in the future so the order needs to be passed explicitly in
order to keep the current behavior.
  • Loading branch information
wshanks committed Nov 14, 2024
1 parent 5321491 commit 1741e9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions qiskit_experiments/library/tomography/fitters/cvxpy_lstsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ def cvxpy_linear_lstsq(
idx = 0
for i in range(num_circ_components):
for j in range(num_tomo_components):
model = bms_r[idx] @ cvxpy.vec(rhos_r[idx]) - bms_i[idx] @ cvxpy.vec(
rhos_i[idx]
model = bms_r[idx] @ cvxpy.vec(rhos_r[idx], order="F") - bms_i[idx] @ cvxpy.vec(
rhos_i[idx], order="F"
)
data = probability_data[i, j]
args.append(model - data)
Expand Down
8 changes: 4 additions & 4 deletions qiskit_experiments/library/tomography/fitters/cvxpy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ def partial_trace_constaint(
ptr = partial_trace_super(input_dim, output_dim)
vec_cons = np.ravel(constraint, order="F")
return [
ptr @ cvxpy.vec(mat_r) == vec_cons.real.round(12),
ptr @ cvxpy.vec(mat_i) == vec_cons.imag.round(12),
ptr @ cvxpy.vec(mat_r, order="F") == vec_cons.real.round(12),
ptr @ cvxpy.vec(mat_i, order="F") == vec_cons.imag.round(12),
]


Expand Down Expand Up @@ -274,7 +274,7 @@ def trace_preserving_constaint(
output_dim = sdim // input_dim

ptr = partial_trace_super(input_dim, output_dim)
cons = [ptr @ cvxpy.vec(arg_r) == np.identity(input_dim).ravel()]
cons = [ptr @ cvxpy.vec(arg_r, order="F") == np.identity(input_dim).ravel()]

if hermitian:
return cons
Expand All @@ -286,7 +286,7 @@ def trace_preserving_constaint(
arg_i = mat_i
else:
raise TypeError("Input must be a cvxpy variable or list of variables")
cons.append(ptr @ cvxpy.vec(arg_i) == np.zeros(input_dim**2))
cons.append(ptr @ cvxpy.vec(arg_i, order="F") == np.zeros(input_dim**2))
return cons


Expand Down

0 comments on commit 1741e9f

Please sign in to comment.