-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Feature request: web app integration #175
Comments
Thanks for the suggestion and for highlighting the challenge for running MINLP solutions in Pyodide. The Pyodide project looks very interesting with bringing Python functionality to the web-browser. I've added this as a feature request. I'm not sure if the mixed Fortran90 / C++ code will compile into WebAssembly with |
@APMonitor I wonder if this project might help? |
Thanks for the link. Another way to tackle this is to set up a Flask server that can handle your MINLP request with a JavaScript version of a Gekko. Here's an example setup: HTML + JavaScript:This code creates a simple form in HTML to input the initial value for the variable <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Gekko Optimization via JavaScript</title>
</head>
<body>
<h1>Simple Gekko Solver</h1>
<form id="gekkoForm">
<label for="initialY">Initial y value:</label>
<input type="text" id="initialY" name="initialY" value="2">
<button type="button" onclick="sendData()">Solve</button>
</form>
<div id="result"></div>
<script>
function sendData() {
var initialY = document.getElementById('initialY').value;
fetch('http://your-server-address/solve', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({initialY: initialY})
})
.then(response => response.json())
.then(data => {
document.getElementById('result').innerText = 'Solution y: ' + data.result;
})
.catch((error) => {
console.error('Error:', error);
});
}
</script>
</body>
</html> Python Server Code:This is a simple Flask server application that receives the initial value, solves the optimization problem using Gekko, and sends back the result. from flask import Flask, request, jsonify
from gekko import GEKKO
app = Flask(__name__)
@app.route('/solve', methods=['POST'])
def solve():
data = request.get_json()
initial_y = float(data['initialY'])
m = GEKKO() # Create GEKKO model
y = m.Var(value=initial_y) # Define variable, initial value from JS
m.Equation(y**2 == 1) # Define equation
m.solve(disp=False) # Solve
return jsonify(result=y.value[0])
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000) Deployment:
This setup assumes that the server hosting the Python code is accessible through The other option is to use the public server and have your pyiodide application create a |
@APMonitor Unfortunately, establishing such a backend is beyond the scope of my project. My main goal is to provide offline capability to my web app, so WASM solutions will be the top choices, and if I really need to do this with remote APIs, I might as well just use one from the NEOS server. |
My web app is looking for a MINLP solver, and I came across GEKKO which works perfectly for my use case when running locally. I was hoping to run GEKKO through Pyodide, but that seems impossible at this point, for:
I would really love to see a solution to this. This can be done by creating a Pyodide-compatible build of GEKKO, or by directly compiling APMonitor into WebAssembly and call it from JavaScript.
The text was updated successfully, but these errors were encountered: