qsearch.assemblers

This module defines the Assembler class, which is used to convert a Qsearch-style circuit into other formats, such as Qiskit or Qasm.

The DictionaryAssembler subclass is provided as the default implementation of an Assembler. Use it as-is or as an example for writing your own Assembler. Some constants are also defined as DictionaryAssembler instances preloaded with the most common assembly dictionaries.

qsearch.assemblers.ASSEMBLER_QISKIT

Outputs Python code that generates a Qiskit circuit object.

qsearch.assemblers.ASSEMBLER_OPENQASM

Outputs generic Openqasm code. This may not be compatible with IBM Qiskit.

qsearch.assemblers.ASSEMBLER_IBMOPENQASM

Outputs Openqasm code with the IBM imports and gate names. This flavor of Openqasm is compatible with IBM Qiskit.

qsearch.assemblers.ASSEMBLER_QUTRIT

Outputs pseudocode for circuits built with single-qutrit gates and CNOTs.

Module Contents

Classes

Assembler

This class is used to translate Qsearch-style circuits to other formats.

DictionaryAssembler

This subclass of Assembler uses a dictionary that specifies mappings from gate names to output code, as well as an output code initial line.

Functions

flatten_intermediate(intermediate)

This is a helper function for working with the intermediate tuple language that is output by the assemble method of QuantumStep objects.

Attributes

assemblydict_qiskit

assemblydict_openqasm

assemblydict_ibmopenqasm

assemblydict_qutrit

ASSEMBLER_QISKIT

ASSEMBLER_OPENQASM

ASSEMBLER_IBMOPENQASM

ASSEMBLER_QUTRIT

class qsearch.assemblers.Assembler(options=Options())

This class is used to translate Qsearch-style circuits to other formats.

abstract assemble(resultdict, options=None)

The assemble function is used to convert the circuit described in resultdict. See DictionaryAssembler for an example implementation.

Parameters:

resultdict – The dictionary representing the desired circuit. It is expected to contain the entries “stucture” and “parameters”. It may contain other entries.

Returns:

A string representing the converted circuit code.

Return type:

str

class qsearch.assemblers.DictionaryAssembler(options=Options())

Bases: Assembler

This subclass of Assembler uses a dictionary that specifies mappings from gate names to output code, as well as an output code initial line.

Options: assemblydict (required) : A dictionary that specifies mappings from gate names to output code.

assemble(resultdict, options=None)

The assemble function is used to convert the circuit described in resultdict. See DictionaryAssembler for an example implementation.

Parameters:

resultdict – The dictionary representing the desired circuit. It is expected to contain the entries “stucture” and “parameters”. It may contain other entries.

Returns:

A string representing the converted circuit code.

Return type:

str

qsearch.assemblers.flatten_intermediate(intermediate)

This is a helper function for working with the intermediate tuple language that is output by the assemble method of QuantumStep objects.

qsearch.assemblers.assemblydict_qiskit
qsearch.assemblers.assemblydict_openqasm
qsearch.assemblers.assemblydict_ibmopenqasm
qsearch.assemblers.assemblydict_qutrit
qsearch.assemblers.ASSEMBLER_QISKIT
qsearch.assemblers.ASSEMBLER_OPENQASM
qsearch.assemblers.ASSEMBLER_IBMOPENQASM
qsearch.assemblers.ASSEMBLER_QUTRIT