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

Assembling and Exporting

Marc Davis edited this page Apr 30, 2020 · 6 revisions

Assembling with Projects

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 with add_compilation.
  • language - a sc.assembler.QuantumAssembly object. The default value is sc.assembler.ASSEMBLY_IBMOPENQASM. Other provided options are sc.assembler.ASSEMBLY_QISKIT and sc.assembler.ASSEMBLY_OPENQASM. See below for more information.
  • write_location - a filepath to write the output to. The default value is None, causing the output to be returned as a string instead.

Assembling without Projects

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 an sc.circuits.QuantumStep object, returned by calling compile on a SearchCompiler or get_result on a Project.
  • vector - the numpy ndarray of parameters that accompany the circuit, returned by calling compile on a SearchCompiler or get_result on a Project.
  • language - a sc.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 is None, causing the output to be returned as a string instead.

Custom Assembling with DictionaryAssembly

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 of sc.assembler for example dictionaries.

Advanced Custom Assembling with QuantumAssembly Objects

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 a numpy ndarray. For example, for "U3", there would be 3 parameters. For "CNOT", there would be 0, so this ndarray 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].