-
Notifications
You must be signed in to change notification settings - Fork 9
Assembling and Exporting
Once your project has finished running, you can assemble its output:
myproject.assemble(name, language, write_location)
-
name
- the name of the compilation you are assembling. This is the name specified when adding the unitary to the project withadd_compilation
. -
language
- asc.assembler.QuantumAssembly
object. The default value issc.assembler.ASSEMBLY_IBMOPENQASM
. Other provided options aresc.assembler.ASSEMBLY_QISKIT
andsc.assembler.ASSEMBLY_OPENQASM
. See below for more information. -
write_location
- a filepath to write the output to. The default value isNone
, causing the output to be returned as a string instead.
Once you have the circuit
and vector
output from SearchCompiler
, you can assemble it using sc.assembler.assemble
.
import search_compiler as sc
sc.assembler.assemble(circuit, vector, assembly, write_location)
-
circuit
- the circuit structure as ansc.circuits.QuantumStep
object, returned by callingcompile
on aSearchCompiler
orget_result
on aProject
. -
vector
- thenumpy
ndarray
of parameters that accompany thecircuit
, returned by callingcompile
on aSearchCompiler
orget_result
on aProject
. -
language
- asc.assembler.QuantumAssembly
object used to translate the intermediate format into the output format. See below for more information.write_location
- a filepath that the output will be written to. Its default value isNone
, causing the output to be returned as a string instead.
The easiest way to customize the assembly is by using DictionaryAssembly
.
custom_assembly = sc.assembler.DictionaryAssembly(dictionary)
-
dictionary
- The dictionary that defines the assembly conversion. The dictionary should have this entry: -
"initial"
- a string format that is used at the beginning of the assembly output. It is provided with the number of qubits used by the circuit. It then should have entries of this format: -
"Gate Name"
- a string format that is used to implement the specified gate. It is provided with the parameters for the gate, followed by the index or indices of the qubit(s) that the gate is performed on. The provided assembly implementations implement the following gate names:"X"
,"Y"
,"Z"
,"U3"
,"CNOT"
. See the bottom ofsc.assembler
for example dictionaries.
The QuantumAssembly
class is used to convert from our intermediate format to the final output format. DictionaryAssembly
is a the provided implementation of QuantumAssembly
. It must implement two functions:
initialize(dits)
The initialize
function returns a string that is used at the beginning of the assembled output. It is provided dits
, the number of qudits used by the circuit for initialization.
parse(segment)
The parse
function is called once for each gate, and returns the string that should be appended to the assembled output for that gate. It is provided with segment
, a tuple containing information about the assembled gate. This tuple currently has the following format:
-
segment[0]
- currently unused but reserved for future use. -
segment[1]
- gate type identifier as a string. Examples include"X"
,"Y"
,"Z"
,"U3"
, and"CNOT"
. -
segment[2]
- gate parameters as anumpy
ndarray
. For example, for"U3"
, there would be 3 parameters. For"CNOT"
, there would be 0, so thisndarray
will be empty. -
segment[3]
- qubit indices used as a list. For example, single qubit gates would have a list containing a single index, but"CNOT"
would have a list of the form [control, target].