Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Advanced Project Features

Marc Davis edited this page Feb 28, 2020 · 17 revisions

Projects have can be given values for various options to adjust settings such as the search type or gateset.

import search_compiler as sc
myproject = sc.Project("myproject")
myproject["option"] = value

In addition, the Project class has a few management functions.

Project Options

You can configure options that the compiler used by a project using myproject["config_key"] = config_value. The supported keys are described here.

  • threshold is a float that defines the termination condition of the compilation. The compiler will return when it finds a circuit with a error_func value less than this threshold. The default value is 1e-10.
  • gateset is a search_compiler.gatesets.Gateset object that is used by the compiler. The default value is search_compiler.gatesets.QubitCNOTLinear().
  • error_func is a distance function that compares two numpy.matrix objects. It must return float values that greater than or equal to zero such that input matrices that are close to the same will result in outputs close to zero. The default value is search_compiler.utils.matrix_distance_squared.
  • search_type is a string that can be set to "breadth" to perform a breadth-first search, or "greedy" to perform a greedy search using only error_func. When set to any other value, including the default, A* search is performed using heuristic.
  • heuristic is a function that takes a value from error_func and a search depth, and returns a float. It is used to order the priority queue used for searching. Setting this option overrides search_type.
  • solver is a solver object as defined in search_compiler.solver. It is used to set the numerical optimizer used to solve for circuit parameters. The default is search_compiler.solver.COBYLA_Solver().
  • beams can be sets the number of nodes popped off of the priority queue during each search layer. The default is -1. Setting a positive value will cause the compiler to examine multiple search paths in parallel, and may result in faster runtimes. Setting a negative value will have the compiler calculate a number of beams to maximize CPU utilization.

Advanced Project Features

There are a few more features that the Project class provides that might be needed. You may need to remove or reset compilations.

myproject.remove_compilation("gate_name") # deletes all data relating to the specified gate and removes it from the project
myproject.reset() # deletes all in-progress or completed compilation data in the project. You may need this if you decide to tweak compiler parameters.
myproject.reset("gate_name") # deletes all in-progress or completed compilation data for the specified gate. You may need this if the compiler does not always find the same solution for your gate.
myproject.clear() # deletes all data from the project, putting it in the same state as a fresh project.

You can also get output in the form of search_compiler.circuits.QuantumStep objects. More detail on how to use these objects below.

# circuit is a QuantumStep object, and vector is a numpy array of floats, to be used by certain QuantumStep functions
circuit, vector = myproject.get_result("gate_name")

You can use

myproject.status() # to check the overall status of a project
myproject.status(name) # to check the status of a specific circuit in a project

A note on accessing Projects from multiple processes

You can access a project from a separate process while it is running in another process. You can use project.status() from the second process in order to check on the status of a project without stopping it. If you change project settings or add or remove compilations while it is running in another process, changes will not take effect until that process is stopped and restarted. It is not recommended to attempt to run a project from two processes at the same time.

Clone this wiki locally