ForEachBlockPass
- class ForEachBlockPass(loop_body, calculate_error_bound=False, collection_filter=None, replace_filter='always', batch_size=None)[source]
Bases:
BasePass
A pass that executes other passes on each block in the circuit.
This is a control pass that executes a workflow on every block in the circuit. This will be done in parallel.
- __init__(loop_body, calculate_error_bound=False, collection_filter=None, replace_filter='always', batch_size=None)[source]
Construct a ForEachBlockPass.
- Parameters:
loop_body (
WorkflowLike
) – The workflow to execute on every block.calculate_error_bound (
bool
) – If set to true, will calculate errors on blocks after running loop_body on them and use these block errors to calculate an upper bound on the full circuit error. (Default: False)collection_filter (
Callable[[Operation], bool] | None
) – A predicate that determines which operations should have loop_body called on them. Called with each operation in the circuit. If this returns true, that operation will be formed into an individual circuit and passed through loop_body. Defaults to all CircuitGates, ConstantUnitaryGates, and VariableUnitaryGates. #TODO: address importabilityreplace_filter (
ReplaceFilterFn | str | None
) –A predicate that determines if the resulting circuit, after calling loop_body on a block, should replace the original operation. Called with the circuit output from loop_body and the original operation. If this returns true, the operation will be replaced with the new circuit. Defaults to always replace. If none is passed, will generate a replace filter always replaces. If a string is passed, will generate a replace filter corresponding to the string. The string should either be ‘always’, ‘less-than’, ‘less-than-multi’, ‘less-than-many’, ‘less-than-respecting’, ‘less-than-respecting-multi’, or ‘less-than-respecting-many’.
’always’ will always replace
- ’less-than’ will replace if the new circuit has fewer
gates than the old circuit.
- ’less-than-multi’ will replace if the new circuit has
fewer multi-qudit gates than the old circuit.
- ’less-than-many’ will replace if the new circuit has
fewer many-qudit gates than the old circuit.
- ’less-than-respecting’ will replace if the new circuit
has fewer gates than the old circuit or the old doesn’t respect the model (ignoring single-qudit gate sets).
- ’less-than-respecting-multi’ will replace if the new
circuit has fewer multi-qudit gates than the old circuit or the old doesn’t respect the model (ignoring single-qudit gate sets).
- ’less-than-respecting-many’ will replace if the new
circuit has fewer many-qudit gates than the old circuit or the old doesn’t respect the model (ignoring single-qudit gate sets).
- ’less-than-respecting-fully’ will replace if the new
circuit has fewer gates than the old circuit or the old doesn’t respect the model.
- ’less-than-respecting-fully-multi’ will replace if
the new circuit has fewer multi-qudit gates than the old circuit or the old doesn’t respect the model.
- ’less-than-respecting-fully-many’ will replace if
the new circuit has fewer many-qudit gates than the old circuit or the old doesn’t respect the model.
Defaults to ‘always’. #TODO: address importability
batch_size (
int
) – (Deprecated).
Attributes
The key in data, where block data will be put.
The name of the pass.
Data specific to the processing of individual blocks in a partitioned circuit can be injected into the PassData in run by using this prefix.
If a key exists in the pass data with this prefix, pass it to blocks.
Methods
execute
(*args, **kwargs)Map a function over iterable arguments in parallel.
get_connectivity
(_, data)Retrieve the current connectivity of the circuit.
get_model
(_, data)Retrieve the machine model from the data dictionary.
get_placement
(_, data)Retrieve the logical to physical qubit map from the data dictionary.
get_target
(_, data)Retrieve the target from the data dictionary.
in_parallel
(data)Return true if pass is being executed in a parallel.
run
(circuit, data)Perform the pass's operation, see
BasePass
for more.