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:
- Bad style
- 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.
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_onceto the circuit.qbraid-qir/qbraid_qir/cirq/passes.py
Lines 34 to 43 in 3ef504f
For the majority of use-cases, this works. However, it is:
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_circuitwithout the clunky helpers.