-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
What should we add?
The current way the Target
performs addition of global operations and variadics, where they are treated as if they were regular operations with specific properties per qargs, where these operations should not have any specific qargs or properties.
The way that a global operation or a variadic are addressed are by adding an entry to the Target
's gate map which looks like the following:
Python:
{ None : None }
or
Rust
{ Qargs::Global, None }
In the case of a global operation, the name is added into a mapping onto the number of qubits of said operation which allow us to identify whatever qargs it can operate on.
Proposed changes
What should be done in these cases is to not add global or variadic operations to the Target
's qarg_gate_map
because these operations should not have qargs nor properties. Instead, we should be able to derive the type of operation these are by the currently existing mappings and instead store a None
into the gate_map
's entry.
This would prevent us from accidentally adding properties to these operations, as was intended when the Target
was first created. It should also remove the need for using optional qargs in the core data model for the Target
in rust, as we had to create our own representation that addresses shortcomings of using Option in mappings, see #14210 and would fix some strange behaviors. For example:
Asking the Target
if an operation can operate on qargs None
or Qargs::Global
should only return variadic operations, as global operations operate on any collection of qargs of the right amount.
target = Target("Test")
# Add a cx gate as a global by not specifying properties.
target.add_instruction(CXGate())
# Add an 'IfElseOp' as a variadic.
target.add_instruction(IfElseOp, name="ifelse")
target.operation_names_for_qargs(None)
> {'cx', 'ifelse'}
# 'cx' should not operate on None as it would need a combination of qubits of size two to operate, which None doesn't represent.