qml.estimator.ops.ChangeOpBasis

class ChangeOpBasis(compute_op, target_op, uncompute_op=None, wires=None)[source]

Bases: ResourceOperator

Change of Basis resource operator.

This symbolic class can be used to represent a change of basis operation with a compute-uncompute pattern. This is a special type of operator which can be expressed as \(\hat{U}_{compute} \cdot \hat{V} \cdot \hat{U}_{uncompute}\). If no uncompute_op is provided then the adjoint of the compute_op is used by default.

Parameters:
  • compute_op (ResourceOperator) – A resource operator representing the basis change operation.

  • target_op (ResourceOperator) – A resource operator representing the base operation.

  • uncompute_op (ResourceOperator | None) – An optional resource operator representing the inverse of the basis change operation. If no uncompute_op is provided then the adjoint of the compute_op is used by default.

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

Resources:

This symbolic class represents a product of the three provided operations. The resources are defined trivially as the sum of the costs of each.

See also

The corresponding PennyLane operation ChangeOpBasis.

Example

The change of basis operation can be constructed as follows with each operation defining the compute-uncompute pattern being a valid ResourceOperator:

>>> import pennylane.estimator as qre
>>> compute_u = qre.Hadamard()
>>> base_v = qre.Z()
>>> cb_op = qre.ChangeOpBasis(compute_u, base_v)
>>> print(qre.estimate(cb_op, gate_set={"Z", "Hadamard", "Adjoint(Hadamard)"}))
--- Resources: ---
 Total wires: 1
    algorithmic wires: 1
    allocated wires: 0
         zero state: 0
         any state: 0
 Total gates : 3
  'Adjoint(Hadamard)': 1,
  'Z': 1,
  'Hadamard': 1

We can also set the uncompute_op directly.

>>> uncompute_u = qre.Hadamard()
>>> cb_op = qre.ChangeOpBasis(compute_u, base_v, uncompute_u)
>>> print(qre.estimate(cb_op, gate_set={"Z", "Hadamard", "Adjoint(Hadamard)"}))
--- Resources: ---
 Total wires: 1
    algorithmic wires: 1
    allocated wires: 0
         zero state: 0
         any state: 0
 Total gates : 3
  'Z': 1,
  'Hadamard': 2

resource_keys

resource_params

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

resource_keys = {'cmpr_compute_op', 'cmpr_target_op', 'cmpr_uncompute_op', 'num_wires'}
resource_params

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

Returns:

A dictionary containing the resource parameters:
  • cmpr_compute_op (CompressedResourceOp): A compressed resource operator, corresponding to the compute operation.

  • cmpr_target_op (CompressedResourceOp): A compressed resource operator, corresponding to the base operation.

  • cmpr_uncompute_op (CompressedResourceOp): A compressed resource operator, corresponding to the uncompute operation.

  • num_wires (int): the number of wires this operator acts upon

Return type:

dict

controlled_resource_decomp(num_ctrl_wires, ...)

Returns a list representing the resources for a controlled version of the operator.

resource_decomp(cmpr_compute_op, ...)

Returns a list representing the resources of the operator.

resource_rep(cmpr_compute_op, cmpr_target_op)

Returns a compressed representation containing only the parameters of the operator that are needed to estimate the resources.

classmethod controlled_resource_decomp(num_ctrl_wires, num_zero_ctrl, target_resource_params)[source]

Returns a list representing the resources for a controlled version of the operator.

Parameters:
  • num_ctrl_wires (int) – the number of qubits the operation is controlled on

  • num_zero_ctrl (int) – the number of control qubits, that are controlled when in the \(|0\rangle\) state

  • target_resource_params (dict) – A dictionary containing the resource parameters of the target operator.

Resources:

The resources are derived from the identity \(C(U V U^\dagger) = U C(V) U^\dagger\). Since the compute and uncompute operators cancel each other out when the control is off, only the target operation \(V\) needs to be controllled. The compute and uncompute operations remain uncontrolled.

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_decomp(cmpr_compute_op, cmpr_target_op, cmpr_uncompute_op, num_wires)[source]

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

Parameters:
  • cmpr_compute_op (CompressedResourceOp) – A compressed resource operator, corresponding to the compute operation.

  • cmpr_target_op (CompressedResourceOp) – A compressed resource operator, corresponding to the base operation.

  • cmpr_uncompute_op (CompressedResourceOp) – An optional compressed resource operator, corresponding to the uncompute operation. The adjoint of the cmpr_compute_op is used by default.

Resources:

This symbolic class represents a product of the three provided operations. The resources are defined trivially as the sum of the costs of each.

See also

The corresponding PennyLane operation ChangeOpBasis.

Example

The change of basis operation can be constructed as follows with each operation defining the compute-uncompute pattern being a valid ResourceOperator:

>>> import pennylane.estimator as qre
>>> compute_u = qre.Hadamard()
>>> base_v = qre.Z()
>>> cb_op = qre.ChangeOpBasis(compute_u, base_v)
>>> print(qre.estimate(cb_op, gate_set={"Z", "Hadamard", "Adjoint(Hadamard)"}))
--- Resources: ---
 Total wires: 1
    algorithmic wires: 1
    allocated wires: 0
             zero state: 0
             any state: 0
 Total gates : 3
  'Adjoint(Hadamard)': 1,
  'Z': 1,
  'Hadamard': 1

We can also set the uncompute_op directly.

>>> uncompute_u = qre.Hadamard()
>>> cb_op = qre.ChangeOpBasis(compute_u, base_v, uncompute_u)
>>> print(qre.estimate(cb_op, gate_set={"Z", "Hadamard", "Adjoint(Hadamard)"}))
--- Resources: ---
 Total wires: 1
    algorithmic wires: 1
    allocated wires: 0
         zero state: 0
         any state: 0
 Total gates : 3
  'Z': 1,
  'Hadamard': 2
classmethod resource_rep(cmpr_compute_op, cmpr_target_op, cmpr_uncompute_op=None, num_wires=None)[source]

Returns a compressed representation containing only the parameters of the operator that are needed to estimate the resources.

Parameters:
  • cmpr_compute_op (CompressedResourceOp) – A compressed resource operator, corresponding to the compute operation.

  • cmpr_target_op (CompressedResourceOp) – A compressed resource operator, corresponding to the base operation.

  • cmpr_uncompute_op (CompressedResourceOp) – An optional compressed resource operator, corresponding to the uncompute operation. The adjoint of the cmpr_compute_op is used by default.

  • num_wires (int) – an optional integer representing the number of wires this operator acts upon

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

Contents

Using PennyLane

Release news

Development

API

Internals