<jupyter_start><jupyter_text>![image.png](attachment:image.png)  Problem data<jupyter_code>S = [
    [1,0,0,0,0,0],
    [-1,1,0,0,0,0],
    [-1,0,1,0,0,0],
    [0,-1,0,2,-1,0],
    [0,0,0,0,1,0],
    [0,-2,1,0,0,1],
    [0,0,-1,1,0,0],
    [0,0,0,0,0,-1],
    [0,0,0,-1,0,0],
]
vmax = [ 10.10, 100, 5.90, 100, 3.70, 100, 100, 100, 100]

S = np.array(S).T
vmax = np.array(vmax).reshape((-1,1))


S.shape, vmax.shape<jupyter_output><empty_output><jupyter_text>Solving<jupyter_code>m,n = S.shape

v = cp.Variable((n,1), name = 'v', nonneg = True)
obj = cp.Maximize(v[n-1])
vmax_ = cp.Parameter(vmax.shape, value = vmax.copy())

C = [
    S @ v == 0,
    v <= vmax_,
]
prob = cp.Problem(obj,C)
prob.solve()
assert prob.status == cp.OPTIMAL
max_growth = v[n-1,0].value
print("max growth rate:", max_growth)
# Reactions limits with nonzero dual value => limit is tight
print(np.arange(1,n+1,1)[(prob.constraints[1].dual_value > 1e-8).ravel()])
# equivalent
np.arange(1,n+1,1)[(vmax - v.value < 1e-8).ravel()]
# Reaction limit that affects most the objective
'R' + str(prob.constraints[1].dual_value.ravel().argmax() + 1)<jupyter_output><empty_output><jupyter_text>Essetial Genes ![image.png](attachment:image.png)<jupyter_code>essential = set()
lb = 0.2 * max_growth
print('lb = ',lb)
vmax_.value = vmax.copy()

for i in range(n):
    aux = vmax_.value[i,0]
    vmax_.value[i,0] = 0
    prob.solve()
    assert prob.status == cp.OPTIMAL
    if v[n-1,0].value < lb:
        essential.add(i)
    vmax_.value[i,0] = aux
    
synthetic_letal = set()
for i in range(n):
    if i in essential: continue
    for j in range(i+1,n):
        if j in essential: continue
        a1 = vmax_.value[i,0]
        a2 = vmax_.value[j,0]
        vmax_.value[i,0] = 0
        vmax_.value[j,0] = 0
        prob.solve()
        assert prob.status == cp.OPTIMAL
        if v[n-1,0].value < lb:
            synthetic_letal.add((i,j))
        vmax_.value[i,0] = a1
        vmax_.value[j,0] = a2
            
        
    
print('essential:', np.array(list(essential))+1)
print('synthetic letal:\n', np.array(list(synthetic_letal))+1)<jupyter_output>lb =  2.7099999993903383
essential: [1 9]
synthetic letal:
 [[2 3]
 [2 7]
 [5 7]
 [4 7]]
{'fraction_non_alphanumeric': 0.19845944721341188, 'fraction_numerical': 0.069777979157227, 'mean_word_length': 3.246153846153846, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '441526', 'license': 'Apache-2.0', 'n_tokens_mistral': 1044, 'n_tokens_neox': 966, 'n_words': 171, 'path': 'Unconstrained minimization/Flux balance analysis in systems biology.ipynb', 'repo_name': 'lpierezan/cvx_course', 'size': '2207'}