mimiqcircuits.operations.rescaledgates

Rescaled gate operation.

Functions

evaluate(param, d)

Return param with the symbols in d substituted; non-symbolic values are returned unchanged.

Classes

RescaledGate(gate, p)

A gate multiplied by a scalar factor p.

class RescaledGate(gate, p)[source]

Bases: AbstractOperator, Generic[T]

A gate multiplied by a scalar factor p.

Represents the operator \(p\,U\), where \(U\) is the matrix of gate. For p < 1 the result is not unitary, so a RescaledGate is an operator, not a gate: it cannot be pushed to a circuit directly or inverted. It is used where an operator is expected, for example in ExpectationValue, or as a Kraus operator of MixedUnitary, where RescaledGate(U, s) stands for \(U\) applied with probability \(s^2\).

Parameters:
  • gate (Gate) – The gate to rescale.

  • p – The factor, a number in \([0, 1]\) or a symbolic expression. Symbolic factors are not range checked.

Raises:

Examples

>>> from mimiqcircuits import *
>>> rg = RescaledGate(GateH(), 0.5)
>>> rg
0.5*H
>>> rg.get_scale()
0.5
>>> rg.matrix()
[0.353553390593274, 0.353553390593274]
[0.353553390593274, -0.353553390593274]

>>> # rescaling again multiplies the factors
>>> rg.rescale(0.8)
0.4*H
>>> # use it as the observable of an expectation value
>>> Circuit().push(ExpectationValue(RescaledGate(GateZ(), 0.5)), 0, 0)
1-qubit, 1-zvar circuit with 1 instruction:
└── ⟨0.5*Z⟩ @ q[0], z[0]
iswrapper()[source]

Return True: a rescaled gate wraps another gate.

getparams()[source]

Return [p, *gate.getparams()].

get_operation()[source]

Return the wrapped gate.

get_param(name)[source]

Return the factor for name == "p", otherwise look name up on the wrapped gate.

opsquared()[source]

Return \((pU)^\dagger (pU) = |p|^2 I\) as a rescaled identity.

get_scale()[source]

Return the factor p.

rescale(p)[source]

Return a new RescaledGate of the same gate with factor self.p * p.

rescale_inplace(p)[source]

Multiply the factor by p in place and return self.

The product is not range checked.

evaluate(d)[source]

Substitute symbols in the factor and in the wrapped gate.

Parameters:

d (dict) – Map from symbols to the values to substitute.

Returns:

self if nothing is symbolic, otherwise a new rescaled gate.

Return type:

RescaledGate

evaluate(param, d)[source]

Return param with the symbols in d substituted; non-symbolic values are returned unchanged.