{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "bdfa18a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from upoqa.problems import *\n",
    "from profiles import plot_performance_profile_noise_free, plot_data_profile_noise_free, plot_speedup_profile_noise_free\n",
    "from utils import *\n",
    "from solvers import *\n",
    "plt.style.use('default')\n",
    "loaded_info = problem_set.load_problem_set(\"s2mpj_prob_set_v1\")\n",
    "\n",
    "problem_idx_range = problem_set.valid_problem_idx()\n",
    "if problem_set.enabled_problem_set == \"s2mpj_prob_set_v1\":\n",
    "    black_list = [\n",
    "        54, # \"MINSURF\"  # all solvers start from 1.0000000000000007 and end with 1.0000000000000007, meaningless\n",
    "    ]\n",
    "    for idx in black_list:\n",
    "        problem_idx_range.remove(idx)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6324fea",
   "metadata": {},
   "source": [
    "# Performance Profile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87be82a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33536 characters]",
      "text/plain": [
       "<Figure size 500x340 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ftol = 1e-5\n",
    "\n",
    "solver_identifier_plot_labels = [\n",
    "    ('upoqa', None, 'upoqa'),\n",
    "    # ('upoqa', 'upoqa (non-struct)', 'upoqa (non-struct)'),\n",
    "    ('upoqa (single)', None, 'upoqa (single)'),\n",
    "    ('l-bfgs-b (ffd)', None, 'l-bfgs-b (ffd)'),\n",
    "    # ('newuoa', None, 'newuoa'),\n",
    "    ('bobyqa', None, 'bobyqa'),\n",
    "    # ('cobyqa', None, 'cobyqa'),\n",
    "]\n",
    "\n",
    "_, figg, axx = plot_performance_profile_noise_free(\n",
    "    solver_labels = [x[0] for x in solver_identifier_plot_labels],\n",
    "    solver_identifiers = [x[1] for x in solver_identifier_plot_labels],\n",
    "    plot_labels = [x[2] for x in solver_identifier_plot_labels],\n",
    "    problem_idx_range = problem_idx_range,\n",
    "    ftol = ftol,\n",
    "    fig_size = (5, 3.4),\n",
    "    grid_on = False,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77926c7d",
   "metadata": {},
   "source": [
    "# Data Profile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "807e812a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 32764 characters]",
      "text/plain": [
       "<Figure size 500x340 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ftol = 1e-5\n",
    "    \n",
    "solver_identifier_plot_labels = [\n",
    "    ('upoqa', None, 'upoqa'),\n",
    "    # ('upoqa', 'upoqa (non-struct)', 'upoqa (non-struct)'),\n",
    "    ('upoqa (w.o. ps)', None, 'upoqa (single)'),\n",
    "    ('l-bfgs-b (ffd)', None, 'l-bfgs-b (ffd)'),\n",
    "    # ('newuoa', None, 'newuoa'),\n",
    "    ('bobyqa', None, 'bobyqa'),\n",
    "    # ('cobyqa', None, 'cobyqa'),\n",
    "]\n",
    "\n",
    "_, _, figg, axx = plot_data_profile_noise_free(\n",
    "    solver_labels = [x[0] for x in solver_identifier_plot_labels],\n",
    "    solver_identifiers = [x[1] for x in solver_identifier_plot_labels],\n",
    "    plot_labels = [x[2] for x in solver_identifier_plot_labels],\n",
    "    problem_idx_range = problem_idx_range,\n",
    "    ftol = ftol,\n",
    "    fig_size = (5, 3.4),\n",
    "    grid_on = False,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b1d44c80",
   "metadata": {},
   "source": [
    "# Speed-up Profile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9018b6bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 24228 characters]",
      "text/plain": [
       "<Figure size 600x335 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 32396 characters]",
      "text/plain": [
       "<Figure size 600x335 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 37856 characters]",
      "text/plain": [
       "<Figure size 600x335 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "solver_identifier_and_names = [\n",
    "    (None, \"bobyqa\"),\n",
    "    (None, \"l-bfgs-b (ffd)\"),\n",
    "    (None, \"upoqa_(single)\"),\n",
    "    (None, \"upoqa\"),\n",
    "]\n",
    "\n",
    "ftols = [1e-1, 1e-4, 1e-7]\n",
    "ftolstr = [-1, -4, -7]\n",
    "fig_size = (6, 3.35)\n",
    "plot_fig_and_ax = None\n",
    "for i in range(len(ftols)):\n",
    "    ftol = ftols[i]\n",
    "    _, figg, axx = plot_speedup_profile_noise_free(\n",
    "        solver_labels = [x[1] for x in solver_identifier_and_names],\n",
    "        solver_identifiers = [x[0] for x in solver_identifier_and_names],\n",
    "        problem_idx_range = problem_idx_range,\n",
    "        plot_label = r\"$\\epsilon = 10^{\" + f\"{ftolstr[i]}\" + r\"}$\",\n",
    "        plot_fig_and_ax = plot_fig_and_ax,\n",
    "        ftol = ftol,\n",
    "        fig_size = fig_size,\n",
    "        # fmt = 'r--'\n",
    "        # grid_on = False,\n",
    "    )\n",
    "    plot_fig_and_ax = (figg, axx)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
