Skip to content

Source code templates for solvers#

Introduction#

In this page you can download source code templates for the different Hardware SDKs and providers, so it is easier to start implementing your solvers.

Templates by Hardware SDK#

Important

Make sure to download the appropriate template according to the Hardware SDK that you selected in your solver. Otherwise, the executions may fail in the platform.

Classical CPU

Classical CPU#

In the following table you can find all the available templates for Classical CPUs:

Language Description Download
Python Template in Python for classical CPUs Available soon

IBM Qiskit

IBM Qiskit#

In the following table you can find all the available templates for IBM Qiskit:

Language Description Download
Python Template in Python for IBM Qiskit Available soon

AWS Braket

AWS Braket#

In the following table you can find all the available templates for AWS Braket:

Language Description Download
Python Template in Python for classical AWS Braket Available soon

Dwave

Dwave#

In the following table you can find all the available templates for Dwave:

Language Description Download
Python Template in Python for Dwave Available soon

Description of the templates#

All the source code templates contain 4 main files:

  • app.py
  • main.py
  • requirements.txt
  • README.md

main.py#

The main.py file contains the run() function with is the entrypoint of the solver.

This run() function recieves the input parameters needed for the execution:

  • input_data
  • solver_params
  • extra_arguments

Definition of the run() function:

def run(input_data:dict, solver_params:dict, extra_arguments:dict) -> dict:

app.py#

The purpose of this file is for local testing only. When executing your solver in the platform, it will be replaced with the platform’s own file that adds the necessary libraries and that calls the right hardward providers.

Caution

You should not modify this file to ensure that your solver works in both local and production environments.

As you can see in this file, the only thing it does is to call the function run() that we have in the main.py file.

requirements.txt#

Finally we have the requirements.txt file containing the packages used in the solver along with their versions:

requirements.txt
qiskit==0.17.0

In your environment, you can install all the packages listed in the requirements.txt file using pip:

pip install -r requirements.txt

Any libraries from the standard approved ones in pip will be instaled. So make sure you add all your code dependencies (except for the Python standard libraries, such as json, logging or time).

Tip

We recommend to use Python virtual environments in your local machine to avoid conflicts with dependencies.

README.md#

It is required to have in the root of the repository a README.md or [solver-name].md file that contains the documentation you want to include about your solver, explaining, if any, the parameters that can be inserted by the end user.

Example of MyFirstSolver.md file:

MyFirstSolver.md
    ## MyFirstSolver
    Test documentation associated with my solver.
    I don't have auxiliary parameters but I could define them like this:
    - "parameter1": (int) This is what my first parameter does.

Run the solver locally#

To run your solver locally during the development process and before uploading it to the platform, just run the app Python script of the solver:

python app.py

Usage instructions#

  1. Download the template you need depending on the Hardware SDK you want to use.
  2. Unzip it in your local machine. It contains 4 main files:
    • app.py
    • main.py
    • requirements.txt
    • README.md
  3. Modify the files to add your own algorithm
  4. Push all the files to the root folder of a git repository
  5. Now you can go to the platform, connect the repository, pull and build your solver, and run jobs.

What’s next#

Connect a repository

Pull and rebuild your solver