This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Advanced Compiler Features
Marc Davis edited this page Apr 30, 2020
·
9 revisions
The SearchCompiler class takes a few optional initializer options.
mycompiler = sc.SearchCompiler.init(threshold, error_func, error_jac, eval_func, heuristic, gateset, solver, beams, logger, verbosity)
-
threshold- a float which specifies the stopping condition for the synthesis. The first circuit for which theerror_funcreturns a value less than thethresholdwill be returned as the solution. The default value is1e-10. -
error_func- a function which takes two matrices and returns a float. Its value is used in guiding the numerical solver. The default value issc.utils.matrix_distance_squared. Usually, its value is also used foreval_func. Ifeval_funcis specified separately,error_funccan behave differently, such as returning an array of residuals instead of a single value when using LeastSquares. -
error_jac- a function which takes two matrices, and returns a tuple of the float that would be returned byerror_func, and the Jacobian of that function. It's value is used by solvers that can take advantage of the Jacobian, such as BFGS and LeastSquares. The default value isNone, and ifNoneis specified, an appropriate value will be chosen based on the value oferror_func. -
eval_func- a function which takes two matrices and returns a float. Whileerror_funcis used to guide the numerical solver,eval_funcis used to guide the search and decide when to return a solution. Its default value isNone, and an appropriate value will be chosen at runtime. Specifically, it will be set tosc.utils.matrix_distance_squarediferror_funcisutils.matrix_residuals, and will be set toerror_funcotherwise. It is necessary to manually change this to use LeastSquares with a customerror_func. -
heuristic- a function which takes the value oferror_funcand the current search depth and returns a float. This value is used to guide the search. The default issc.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- asc.gatesets.Gatesetobject which describes the gateset used for synthesis. The default value issc.gatesets.QubitCNOTLinear(), which is the recommended gateset for using CNOTs and single qubit gates with the linear topology. -
solver- asc.solver.Solverobject which performs numerical optimization. The default value isLeastSquares_Jac_Solverifgatesetis one of the provided gatesets consisting ofCNOTand single qubit gates, orCOBYLA_Solverotherwise. If the Native Gateset is installed, it will be used if it is supported by the givengateset. -
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. -
logger- ansc.logging.Loggerobject that the compiler will use for logging. The default value isNone. See the wiki page for more information. -
verbosity- ifloggeris left asNone, then a logger will be created that prints to stdout with the specified verbosity. The default value is0. A value of0will silence all output, a value of1will produce a default level of output, and a value of2will produce more detailed output. See the wiki page for more information.
The compile function of the SearchCompiler class also can take two extra parameters:
circuit, vector = mycompiler.compile(U, depth, statefile, logger)
-
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 thethresholdcondition, then the circuit with the lowest value oferror_funcwill be returned. The default value ofNonewill result in no depth limit being used, and the search will continue indefinitely until a circuit that meets thethresholdrequirement 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. -
logger- asc.logging.Loggerobject that can be used to override the logging settings provided on creating theSearchCompilerobject. The default value isNone, which causes the logger defined when creating theSearchCompiler` object to be used. See the wiki page for more information.
The compile function of the SearchCompiler returns a tuple of two values:
circuit, vector = mycompiler.compile(U, depth, statefile, logger)
-
circuit- This is asc.circuits.QuantumStepobject that contains the final solution circuit structure found by the compiler. -
vector- This is anumpyndarrayobject containing the final solution parameters found by the compiler. These two return values together describe the final circuit, and can be used to generate the implemented matrix or export the circuit to other formats:
U = circuit.matrix(vector) # returns the unitary matrix implemented by the circuit
sc.assembler.assemble(circuit, vector, language, write_location) # assembles the circuit and exports to another format
See the wiki page on assembling and exporting for more details.