Skip to content

Improve circuit pre-processing for Cirq converter with existing gate decomposers  #93

@ryanhill1

Description

@ryanhill1

Before passing an input cirq circuit to the QIR converter, we first decompose the circuit to ensure that it only uses gates / operations that are supported by QIR, see PYQIR_OP_MAP. Right now, to accomplish this, we use a preprocess_circuit function which loops through each operation, and uses a try / except to determine if the operation is supported, and if not, applies a naive cirq.decompose_once to the circuit.

try:
# Try converting to PyQIR. If successful, keep the operation.
_ = map_cirq_op_to_pyqir_callable(operation)
return [operation]
except CirqConversionError:
pass
new_ops = cirq.decompose_once(operation, flatten=True, default=[operation])
if len(new_ops) == 1 and new_ops[0] == operation:
raise CirqConversionError("Couldn't convert circuit to QIR gate set.")
return list(itertools.chain.from_iterable(map(_decompose_gate_op, new_ops)))

For the majority of use-cases, this works. However, it is:

  1. Bad style
  2. Inefficient

Instead, we would like to use one of the built-in Cirq transforms such as cirq.optimize_for_target_gateset to automatically ensure that the input circuit conforms to the supported QIR operations. In doing so, hopefully we can eliminate the try except blocks in passes.py, and re-implement preprocess_circuit without the clunky helpers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cirqRelated to Cirq conversionsenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions