I have a personal website, written in Django, hosted on Webfaction. I am trying to make a web tool in which users enter some numbers, the server receives them on the backend via AJAX, the server takes them as parameter inputs for a certain system of equations and solves it numerically using some Python package, and the server returns the solution via AJAX and Javascript presents it to the user.
This process works flawlessly when I test it on Localhost. But on the Webfaction server, it often crashes after a few iterations of the numerical approximation function, as long as the inputs are not very simple.
Both scipy.optimize.fsolve and scipy.optimize.root produce the issue. I have tried multiple "method"s, and they have all produced the issue. Also, I was originally on Webfaction's $10/mo "1GB RAM, 100GB SSD storage, 1TB bandwidth, shared server" plan, and I tried switching to their $30/mo "4GB RAM, 45GB SSD storage, 2TB bandwidth, 2 CPU cores, cloud server" plan--a setup similar to my Localhost--but this doesn't seem to have made even the slightest difference.
from scipy.optimize import fsolve
import logging
from forms import *
logger = logging.getLogger(__name__)
def dppsubmit(request):
form = ParamsForm(request.POST)
if form.is_valid():
raw_pd = form.cleaned_data['params']
#[...code in which I define "pd" from "raw_pd"...]
def func(x):
outputs = []
i = 1
while i <= len(x):
#[...code in which I generate the output vector...]
outputs.append(y)
i += 1
logger.log(10, "FUNC ITERATION")
return outputs
logger.log(10, "GOT HERE 1")
solution = fsolve(func, np.asarray([[.01]*num_states], dtype=np.float64))
logger.log(10, "GOT HERE 2")
to_return = ",".join(solution.x.tolist())
return render(request, 'personal/output.html', {'output':to_return})
As we can see from the logging messages in the simplified code above, when it is working properly, it logs "GOT HERE 1", followed by "FUNC ITERATION" a number of times, followed by "GOT HERE 2", and then returns a string which represents the solution vector. But instead, it often logs "GOT HERE 1", followed by "FUNC ITERATION" a few times (generally <20), and then crashes the website.
How can I get this numerical estimation to work on the server without crashing it?