Skip to main content

kpsearch -- A Python Package for K-Portfolio Search

The package kpsearch contains methods to search for portfolios of algorithms (e.g., SAT solvers). A portfolio is a set of algorithms, where the portfolio's runtime on a problem instance equals the runtime of the fastest algorithm from the portfolio. This VBS (virtual best solver) approach corresponds to running all the portfolio's algorithms in parallel and only recording the runtime of the fastest algorithm per problem instance. (In reality, one could use a prediction model to choose a (hopefully fast) algorithm for each problem instance.) Given the runtimes of multiple algorithms on multiple problem instances, one wants to find the overall optimal (fastest) portfolio of size k, i.e., containing k algorithms.

This document provides:

If you use this package for a scientific publication, please cite our paper

@inproceedings{bach2022comprehensive,
  author={Bach, Jakob and Iser, Markus and B\"{o}hm, Klemens},
  title={A Comprehensive Study of k-Portfolios of Recent {SAT} Solvers},
  booktitle={25th International Conference on Theory and Applications of Satisfiability Testing (SAT 2022)},
  location={Haifa, Israel},
  year={2022},
  doi={10.4230/LIPIcs.SAT.2022.2}
}

Setup

You can install our package from PyPI:

python -m pip install kpsearch

Alternatively, you can install the package from GitHub:

python -m pip install git+https://github.com/Jakob-Bach/Small-Portfolios.git#subdirectory=code/kpsearch_package

If you already have the source code for the package (i.e., the directory in which this README resides) as a local directory on your computer (e.g., after cloning the project), you can also perform a local install:

python -m pip install kpsearch_package/

Functionality

kpsearch.py provides several functions for searching k-portfolios:

  • exact: exhaustive_search(), mip_search(), smt_search(), smt_search_nof()
  • heuristic: beam_search(), kbest_search(), random_search()

mip_search() is a novel contribution of our paper, using a MIP solver to find optimal k-portfolios. All other search methods are straightforward and/or adaptations from related work. mip_search() is usually the fastest exact search method except for very small or large k (where the plain exhaustive_search() may be faster).

All functions share two parameters:

  • A pandas.DataFrame, where the rows represent problem (e.g., SAT) instances, the columns represent solvers (column names are solver names), and the cells represent runtimes.
  • The portfolio size k, i.e., the maximum number of solvers in the portfolio (some search methods may return smaller portfolios if adding more solvers is not beneficial).

The existence of further parameters depends on the search method; see the individual functions' documentation for details.

All search methods return a list, where each entry is a portfolio described by

  • the solver names (column names from the runtime data) and
  • the objective value (average runtime of the VBS, i.e., virtual best solver, which assumes the lowest runtime of the portfolio members for each instance).

Demo

Let's create a small demo dataset with runtimes of three solvers on four problem instances:

import pandas as pd
import kpsearch

runtimes = pd.DataFrame({'Solver1': [1, 2, 3, 4],
                         'Solver2': [2, 2, 5, 1],
                         'Solver3': [5, 3, 2, 1]})

I.e., the data looks as follows:

   Solver1  Solver2  Solver3
0        1        2        5
1        2        2        3
2        3        5        2
3        4        1        1

Let's try exhaustive search:

print(kpsearch.exhaustive_search(runtimes=runtimes, k=2))

This search procedure returns all portfolios of the desired size k (so if you only wanted the optimal portfolio, you would need to search in these results accordingly):

[(['Solver1', 'Solver2'], 1.75), (['Solver1', 'Solver3'], 1.5), (['Solver2', 'Solver3'], 1.75)]

Let's try greedy search, i.e., a beam search with a beam width of one:

print(kpsearch.beam_search(runtimes=runtimes, k=3, w=1))

This search procedure does not only yield a k-portfolio, but also all intermediate results, i.e., smaller portfolio sizes, since the procedure iteratively adds solvers to the portfolio:

[(['Solver1'], 2.5), (['Solver1', 'Solver3'], 1.5), (['Solver1', 'Solver2', 'Solver3'], 1.5)]

We can see that the third iteration does not improve the portfolio's VBS, i.e., Solver 2 cannot solve any instance faster than both other solvers.

Developer Info

Though there is no formal superclass or interface, all existing search methods follow specific conventions, which makes them compatible with each other. Thus, if you want to add another portfolio-search method, it may be beneficial to follow these conventions as well.

All search methods share two parameters: The solver runtimes as DataFrame and the number of solvers k as int. You can add further method-specific parameters as you like. For example, beam search has the beam width w as another parameter.

The result of each search method is a list of tuples of

  • solver names (list of strings, corresponding to column names in runtimes) and
  • portfolio performance (float) in terms of VBS score.

The list may have a length of one in case the search only returns one portfolio.

Metadata

Release files for kpsearch 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kpsearch 1.0.0
File Size Uploaded
kpsearch-1.0.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kpsearch 1.0.0
File Interpreter ABI Platform
kpsearch-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / kpsearch-1.0.0.tar.gz

Download URL kpsearch-1.0.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a4ecb0b702a2bf91826ad5a206ecf64fc46f066441a304fef046fd695627729c
BLAKE2b-256 checksum
How to use checksums
f27664ccddbf77385d83533244322dbe11a41f618f3816323ce69238cf5963e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.18

Release files / kpsearch-1.0.0-py3-none-any.whl

Download URL kpsearch-1.0.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
095f34b61c82bdf691ee23a2c205713ced9466ad1408d8fe26ea6af3245614fb
BLAKE2b-256 checksum
How to use checksums
aa450820debea66ce098c2c55ce9abf2eac17b224c6c768a83252cb6cee24019
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.18

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page