This repository contains a FastAPI application that exposes an API endpoint for simulating the discrete time dynamical system to approximate the point's position. The simulation parameters are provided in the request payload.
Before installing the simulation application, you need to have the following installed:
-
Python 3.7 or above - check by typing
python -V
. If the output does not start with3.7
or greater, you need to install a later version of Python. Using pyenv is highly recommended! -
Homebrew if you are developing on a Mac.
-
The AWS Command Line Interface - check by typing
aws --version
. The output should start withaws-cli/2.4.2
- if it does not, you need to install AWS CLI.
$ git clone https://github.com/Lin-Wen15/simulation_case_study.git
$ cd simulation_case_study/backend
$ python -m venv .br-venv
$ source .br-venv/bin/activate (On Windows: `.venv\Scripts\activate`)
$ pip install -r requirements.txt
$ pip install fastapi
- Navigate to the
backend/
directory:cd simulation_case_study-root/backend
- Run the simulation application on the local server:
uvicorn main:app --reload
- On a new terminal, submit your POST request. Here's an example curl command with input parameters, you can change the parameters with the same JSON playload:
curl -X POST "http://127.0.0.1:8000/simulations/simulate" -H "Content-Type: application/json" -d '{"x0": 1.0, "y0": 2.0, "z0": 3.0, "sigma": 0.5, "rho": 0.8, "beta": 0.2, "delta_t": 0.01, "n": 20}'
- You can check the detailed information about the available endpoints, request parameters, and response formats at http://127.0.0.1:8000/docs while the server is running.
- Navigate to the
infrastructure/
directory. - Install Terraform and AWS CLI:
brew install terraform
(On Windows:choco install terraform
) - Run the Terraform Commands:
terraform init
terraform plan -var="aws_access_key=your-access-key" -var="aws_secret_key=your-secret-key"
terraform apply -var="aws_access_key=your-access-key" -var="aws_secret_key=your-secret-key"
cd simulation_case_study/backend
python -m unittest tests.test_simulation
- The simulate_system function in dynamical_simulation.py contains the logic for simulating the dynamical system.