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

Advanced Compiler Features

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

Configuring Compiler Options Manually

The SearchCompiler class takes a few optional initializer options.

mycompiler = sc.SearchCompiler.init(threshold, error_func, heuristic, gateset, solver, beams)

Compiler Options

  • threshold - a float which specifies the stopping condition for the synthesis. The first circuit for which the error_func returns a value less than the threshold will be returned as the solution. The default value is 1e-10.
  • error_func - a function which takes two matrices and returns a float. It's value is used in guiding the search and deciding when to return a solution. The default value is sc.utils.matrix_distance_squared.
  • heuristic - a function which takes the value of error_func and the current search depth and returns a float. This value is used to guide the search. The default is sc.heuristics.astar. Heuristics for greedy search and breadth first search are also provided. It is recommended to switch to breadth first search if you are using a gateset with gates other than CNOT and single qubit gates.
  • gateset - a sc.gatesets.Gateset object which describes the gateset used for synthesis. The default value is sc.gatesets.QubitCNOTLinear(), which is the recommended gateset for using CNOTs and single qubit gates with the linear topology.
  • solver - a sc.solver.Solver object which performs numerical optimization. The default value is sc.solver.COBYLA_Solver, which makes a call to sp.optimize.fmin_cobyla for numerical optimization.
  • beams - an integer which defines the number of nodes to expand at a time during each step. A negative value will result in a number of beams calculated to fully utilize the CPU threads visible to Python. The default value is -1.

Compile Function Options

The compile function of the SearchCompiler class also can take two extra parameters:

mycompiler.compile(U, depth, statefile)
  • U - the only required option, which is the unitary to be synthesized
  • depth - an integer which serves as a depth limit. If a circuit is not found within this limit that satisfies the threshold condition, then the circuit with the lowest value of error_func will be returned. The default value of None will result in no depth limit being used, and the search will continue indefinitely until a circuit that meets the threshold requirement is found.
  • statefile - a string that describes a file path that will be used to store the intermediate state of the compilation. If the compilation is interrupted, it can be resumed by making the same call again, and the state will be restored from the statefile. Without a statefile, compilataion will have to start from the beginning if compilation is interrupted.
Clone this wiki locally