qml.estimator.templates.ControlledSequence

class ControlledSequence(base, num_control_wires, wires=None)[source]

Bases: ResourceOperator

Resource class for the ControlledSequence gate.

This operator represents a sequence of controlled gates, one for each control wire, with the base operator raised to decreasing powers of 2.

Parameters:
  • base (ResourceOperator) – The operator to repeatedly apply in a controlled fashion.

  • num_control_wires (int) – the number of controlled wires to run the sequence over

  • wires (Sequence[int], None) – the wires the operation acts on

Resources:

The resources are obtained as a direct result of the definition of the operator:

0: ──╭●───────────────┤
1: ──│────╭●──────────┤
2: ──│────│────╭●─────┤
t: ──╰U⁴──╰U²──╰U¹────┤

See also

The associated PennyLane operation ControlledSequence

Example

The resources for this operation are computed using:

>>> import pennylane.estimator as qre
>>> ctrl_seq = qre.ControlledSequence(
...     base = qre.RX(),
...     num_control_wires = 3,
... )
>>> gate_set={"CRX"}
>>> print(qre.estimate(ctrl_seq, gate_set))
--- Resources: ---
Total wires: 4
    algorithmic wires: 4
    allocated wires: 0
    zero state: 0
    any state: 0
Total gates : 3
'CRX': 3

resource_keys

resource_params

Returns a dictionary containing the minimal information needed to compute the resources.

resource_keys = {'base_cmpr_op', 'num_ctrl_wires'}
resource_params

Returns a dictionary containing the minimal information needed to compute the resources.

Returns:

A dictionary containing the resource parameters:
  • base_cmpr_op (CompressedResourceOp): A compressed resource operator, corresponding to the operator that we will be applying controlled powers of.

  • num_ctrl_wires (int): the number of controlled wires to run the sequence over

Return type:

dict

resource_decomp(base_cmpr_op, num_ctrl_wires)

Returns a list representing the resources of the operator.

resource_rep(base_cmpr_op, num_ctrl_wires)

Returns a compressed representation containing only the parameters of the Operator that are needed to compute the resources.

classmethod resource_decomp(base_cmpr_op, num_ctrl_wires)[source]

Returns a list representing the resources of the operator. Each object in the list represents a gate and the number of times it occurs in the circuit.

Parameters:
  • base_cmpr_op (CompressedResourceOp) – A compressed resource operator, corresponding to the operator that we will be applying controlled powers of.

  • num_ctrl_wires (int) – the number of controlled wires to run the sequence over

Resources:

The resources are obtained as a direct result of the definition of the operator:

0: ──╭●───────────────┤
1: ──│────╭●──────────┤
2: ──│────│────╭●─────┤
t: ──╰U⁴──╰U²──╰U¹────┤
Returns:

A list of GateCount objects, where each object represents a specific quantum gate and the number of times it appears in the decomposition.

Return type:

list[GateCount]

classmethod resource_rep(base_cmpr_op, num_ctrl_wires)[source]

Returns a compressed representation containing only the parameters of the Operator that are needed to compute the resources.

Parameters:
  • base_cmpr_op (CompressedResourceOp) – A compressed resource operator, corresponding to the operator that we will be applying controlled powers of.

  • num_ctrl_wires (int) – the number of controlled wires to run the sequence over

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

Contents

Using PennyLane

Release news

Development

API

Internals