faropt package¶
Subpackages¶
Module contents¶
-
class
faropt.
FarOpt
(framework='ortools', stackname='faropt')¶ Bases:
object
FarOpt class used to initialize, configure and submit jobs to the back end :param framework: Currently only ortools, TO DO is to extend to other frameworks. Note that other frameworks like pyomo, DEAP, inspyred and pulp are supported :type framework: string, optional :param stackname: Points to the backend CDK stack that needs to be launched separately. Default name is faropt, but you many need to pass in another name while testing :type stackname: string, optional
-
add_recipe
(recipe_name, maintainer='Faropt SDK user')¶ Adds a recipe referencing the job that you submitted (see self object params).
- Parameters
recipe_name (string) – Friendly name for your recipe
maintainer – Recipe author/maintainer
-
configure
(source_dir)¶ Zips up a local folder containing your main.py code, and any other subfolders/files required to run your project. Make note of the output structure printed to see if all files that you need are printed.ArithmeticError
- Parameters
source_dir (string) – path to your source, such as ‘./home/src/’
-
get_metric_data
(metric_name)¶ Returns raw metric data that was submitted from the backend. To use this, do from utils import * in your main.py, and then use log_metric like this, for e.g: log_metric(‘total_distance’,total_distance)
- Returns
response from cloudwatch
- Return type
json string
-
get_recipe_id_from_description
(description)¶ Returns UUID of a recipe based on friendly description/ recipe name
- Parameters
description (string) – friendly description/ recipe name
- Returns
First UUID that matches the description of the recipe
- Return type
uuid4()
-
list_jobs
(limit=10, verbose=True)¶ Returns list of jobs submitted
- Parameters
limit (int, optional) – Number of jobs to return, Defaults to 10
verbose (bool, optional) – Verbose print of the job table, Defaults to True
- Returns
job table scan (raw) results
- Return type
boto3 response
-
list_recipes
(limit=10, verbose=True)¶ Returns list of recipes registered
- Parameters
limit (int, optional) – Number of recipes to return, Defaults to 10
verbose (bool, optional) – Verbose print of the recipe table, Defaults to True
- Returns
Recipe table scan (raw) results
- Return type
boto3 response
-
logs
()¶ Prints logs of a submitted job.
-
primary_status
()¶ Returns the last status of the submitted job; Can be PROVISIONING > PENDING > RUNNING > STOPPED > JOB COMPLETED
- Returns
primary staus
- Return type
string
-
printlogs
(response)¶
-
run_recipe
(recipe_id, micro=False)¶ Runs already registered recipe
- Parameters
recipe_id (bool) – UUID of recipe
micro – Submit as a micro job
-
run_s3_job
(bucket, key, micro=False)¶ Runs job based on a source file in bucket/key. For example, place a source.zip in s3://bucket/key/source.zip and submit a job
- Parameters
bucket (string) – Bucket name
key (string) – path/key on S3 that looks like path/to/s3/key/source.zip inside the bucket
micro (bool) – Submit a micro job.
-
stage
()¶ Uploads the source.zip but does not submit to fargate. Useful when you want to run later
-
status
()¶ Returns the full status of the submitted job; used in primary_status, which should be enough for most use cases
-
stop
()¶ Stops a submitted task
-
stream_logs
(start_time=0, skip=0)¶ Internal, use self.logs() instead of streaming
-
submit
(micro=False)¶ Runs job defined in object params. Creates a new job ID to track and sets submitted to True. Check self.jobname to reference the job that was submitted. View self.logs() once the job has completed
- Parameters
micro (bool) – Submit a micro job. By submitting a micro job, you are restricted to using ortools, pyomo and deap libraries for jobs that last up to 5 minutes
-
wait
()¶ Polls for the primary status of the container task that runs this job. You should see PROVISIONING > PENDING > RUNNING > STOPPED > JOB COMPLETED
- Returns
primary status of the job that was submitted
- Return type
list
-