{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# OPTaaS Warm Start\n", "\n", "### Note: To run this notebook, you need an API Key. You can get one here.\n", "\n", "You can \"warm-start\" an OPTaaS Task by providing some results that you've already calculated. This should help you get to the optimum faster." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Connect to OPTaaS using your API Key" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "library(optaas.client)\n", "\n", "client <- OPTaaSClient$new(\"https://optaas.mindfoundry.ai\", \"Your OPTaaS API Key\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define your parameters" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": false }, "outputs": [], "source": [ "parameters <- list(\n", " BoolParameter('my_bool'),\n", " CategoricalParameter('my_cat', values=list('a', 'b', 'c'), default='c'),\n", " ChoiceParameter('ints_or_floats', choices=list(\n", " GroupParameter('ints', items=list(\n", " IntParameter('my_int', minimum=0, maximum=20),\n", " IntParameter('my_optional_int', minimum=-10, maximum=10, optional=TRUE)\n", " )),\n", " GroupParameter('floats', items=list(\n", " FloatParameter('float1', minimum=0, maximum=1),\n", " FloatParameter('float2', minimum=0.5, maximum=4.5)\n", " ))\n", " ))\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define your scoring function\n", "\n", "The argument names in your scoring function must match the parameter names you defined above." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "scoring_function <- function(my_bool, my_cat, ints_or_floats) {\n", " score <- if (isTRUE(my_bool)) 5 else -5\n", " score <- if (my_cat == 'a') score + 1 else score + 3\n", " if (!is.null(ints_or_floats$ints)) {\n", " score <- score + do.call(sum, ints_or_floats$ints)\n", " } else {\n", " score <- score * do.call(sum, ints_or_floats$floats)\n", " }\n", " score\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create your Task" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "task <- client$create_task(\n", " title=\"Dummy task\",\n", " parameters=parameters,\n", " goal=\"min\", # optional (default is \"max\")\n", " min_known_score=-22, max_known_score=44 # optional\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create some warm-start configurations" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "