Skip to content

FelixBot is a discord bot used to visualize vectors and equations (in 2D and 3D) and solve some optimization problems using CVXPY.

Notifications You must be signed in to change notification settings

abdoitman/FelixBot

Repository files navigation

banner 1

Welcome to FelixBot

FelixBot is a discord bot designed to help students visualize spaces and vectors in 2D and 3D using matplotlib. Also, solve optimization problems using CVXPY.

Table of Contents


Functionality

The bot is capable of many things. To make the bot listen to your messages, start the message with f:: followed by the desired command.
Here are the available commands:

  • f::show ... var ... : This is used to display written equation in a better way.

  • f::imagine : This is used to display vector, a set of vectors, or an equation. You have multiple options to draw as follows:

    • f::imagine vector : displays a single vector.
    • f::imagine vectors : displays a set of vectors with # to separate vectors apart.
    • f::imagine equation ... var ... with constraints ... , ... : displays an equation with some constraints.
  • f::optimize : This is used to solve some optimization problems. Define the problem using the following commands:

    • f::optimize func ... var ... with constraints ... : solves general optimization problems
    • f::optimize linear A = [...] # b = [...] # c = [...] : solves LP optimization problems
    • f::optimize quadratic P = [...] # q = [...] # ... : solves quadratic optimization problems
    • f::optimize ls A = [...] # b = [...] : solves least squares problems
  • f::check dt [ [...] , [...] ] : This is used to check the definite type of a matrix and returns its eigenvalues.


Demonstration

Key Features

  • Easy to set up and use.
  • Plot spaces and vectors.
  • Can solve linear program, quadratic program and general functions optimization problems.

Quick Examples

  • Showing an equation in a mathematical form: f::show sin(2*x_1*pi) / sqrt(x_2) var x_1 x_2
    Response:

  • Plotting a set of vectors: f::imagine vectors [2, 3] # [1, 0] # [6,4]
    Response:

  • Plotting equation: f::imagine equation x**2 + y**2 var x y with constraints x > 0

  • Solving an optimization problem: f::optimize linear c=[5, 1, 2, 0, -5, 6 ,0.5] # constraints= [x >= 0, sum(x) == 3]


How To Use

You can use this link to make the bot join your server. Also, note that the bot needs a #bot-help channel to be in the server before it arrives.

The link above will take you to this screen, where you get to choose which of the servers you mange you want to add the bot to.

NOTE: currently the bot is not hosted on any online server, therefore, sadly it's down


How It Works

The project has an architecture of multiple modules that can be classified as follows:


Bot entry point

main

main.py is the main entry point of running the bot. It only calls run_discord_bot() from bot module.

bot module

bot.py contains 3 functions:

  1. run_discord_bot() which is responsible for running the bot. It also defines the behavior of the bot. Among receiving a message that starts with f:: it calls process_message to process the input message.
  2. process_message(user, channel, user_message, client) which calls the process function from the handle_responses module to understand and analyze the input message.
  3. send_message_to_channel(user_id, channel, response) which mentions the user that messaged the bot and sends the response of the bot to the channel.

Taking the input

handle_responses module

handle_responses.py has one main function process which extracts what command the user entered and calls the corresponding response function.

input_commands module

input_commands.py introduces 3 main classes that will be used to define and change the string input message into numeric values and equations. The classes are:

  1. InputParser : parses the input messages into an equation, variables, and constraints.
  2. VectorsParser : parses the input into a vector or multiple vectors.
  3. OptimizationMatriciesParser : this is used to parse the matricies and vectors used as optimization parameters.

validation module

validation.py works hand in hand with input_commands module. It makes sure that the input being fed into the input_command classes is valid.


Executing the input

help module

help.py has one main function; show_general_guide() which returns a general guide about the about and the functionality of it. Also, there are other functions that returns specific, more detailed message about each functionality of the bot.

write_latex module

write_latex.py has a main function which is show_latex. Internal function __save_latex_png uses latex.codecogs to convert the latex into PNG transparent images. After the image is saved, show_latex returns the path to the PNG file.

imagine package

See the documentation of the package here.

optimize module

optimize.py has a main function which is solve which analyzes the input command and calls the corresponding the solver functions; which are:

  1. __optimize_general_functions which solves a general function optimization problem.
  2. __optimize_linear_program which solves LP optimization problem.
  3. __optimize_least_squares which solves a least squares optimization problem.
  4. __optimize_quadratic which solves a quadratic optimization problem.

check module

check.py contains the main function; inspect which chooses the function being executed depending on the user input.
Currently, the only check function is __check_definite_type which checks the definite type of a matrix whether it's positive-definite, positive-semi-definite, negative-definite, ... etc.

About

FelixBot is a discord bot used to visualize vectors and equations (in 2D and 3D) and solve some optimization problems using CVXPY.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages