qp.PCPhase

class PCPhase(phi, dim, wires)[source]

Bases: Operator2

A projector-controlled phase gate.

This gate applies a complex phase \(e^{i\phi}\) to the first \(dim\) basis vectors of the input state while applying a complex phase \(e^{-i \phi}\) to the remaining basis vectors. For example, consider the 2-qubit case where dim = 3:

\[\begin{split}\Pi(\phi) = \begin{bmatrix} e^{i\phi} & 0 & 0 & 0 \\ 0 & e^{i\phi} & 0 & 0 \\ 0 & 0 & e^{i\phi} & 0 \\ 0 & 0 & 0 & e^{-i\phi} \end{bmatrix}.\end{split}\]

This can also be written as \(\Pi(\phi) = \exp(i\phi(2\Pi-\mathbb{I}_N))\), where \(N=2^n\) is the Hilbert space dimension for \(n\) qubits and \(\Pi\) is the diagonal projector with dim ones and N-dim zeros.

Details:

  • Number of wires: Any (the operation can act on any number of wires)

  • Number of parameters: 1

  • Number of dimensions per parameter: (0,)

Parameters:
  • phi (float) – rotation angle \(\phi\)

  • dim (int) – the dimension of the subspace

  • wires (Iterable[int, str], Wires) – the wires the operation acts on

Example:

We can define a circuit using PCPhase as follows:

>>> op_3 = qp.PCPhase(0.27, dim = 3, wires=range(3))

The resulting operation applies a complex phase \(e^{0.27i}\) to the first \(dim = 3\) basis vectors and \(e^{-0.27i}\) to the remaining basis vectors, as we can see from the diagonal of the matrix for this circuit.

>>> print(np.round(np.diag(qp.matrix(op_3)),2))
[0.96+0.27j 0.96+0.27j 0.96+0.27j 0.96-0.27j 0.96-0.27j 0.96-0.27j
 0.96-0.27j 0.96-0.27j]

We can also choose a different dim value to apply the phase shift to a different set of basis vectors as follows:

>>> op_7 = qp.PCPhase(1.23, dim=7, wires=[1, 2, 3])
>>> print(np.round(np.diag(qp.matrix(op_7)),2))
[0.33+0.94j 0.33+0.94j 0.33+0.94j 0.33+0.94j 0.33+0.94j 0.33+0.94j
 0.33+0.94j 0.33-0.94j]

PCPhase operations are decomposed into (multi-)controlled PhaseShift operations which share the same control values on common control wires, and Pauli-X operations, possibly complemented by a global phase.

>>> op_13 = qp.PCPhase(1.23, dim=13, wires=[1, 2, 3, 4])
>>> print(qp.draw(op_13.decomposition)())
1: ─╭●─────────╭●───────────╭GlobalPhase(-1.23)─┤
2: ─╰Rϕ(-2.46)─├●───────────├GlobalPhase(-1.23)─┤
3: ────────────├○───────────├GlobalPhase(-1.23)─┤
4: ──X─────────╰Rϕ(2.46)──X─╰GlobalPhase(-1.23)─┤

If dim is a power of two, a single (multi-controlled) PhaseShift gate is sufficient:

>>> op_16 = qp.PCPhase(1.23, dim=16, wires=range(6))
>>> print(qp.draw(op_16.decomposition, wire_order=range(6), show_all_wires=True)())
0: ────╭○───────────╭GlobalPhase(1.23)─┤
1: ──X─╰Rϕ(2.46)──X─├GlobalPhase(1.23)─┤
2: ─────────────────├GlobalPhase(1.23)─┤
3: ─────────────────├GlobalPhase(1.23)─┤
4: ─────────────────├GlobalPhase(1.23)─┤
5: ─────────────────╰GlobalPhase(1.23)─┤

Resources are general, for \(n\) wires and dim \(=d\). Each circuit shows one example of the rule. Use a rule when decomposing with qp.decompose:

qp.decompose(gate_set=..., fixed_decomps={qp.PCPhase: "<name>"})

_decompose_pcphase

_decompose_pcphase

Example: \(n=4\), \(d=3\)

Gate

Count

Example

PhaseShift with \(i\) controls

\(M\)

2

X

\(2M_+\)

2

GlobalPhase

\(1\)

1

where \(d = f\,2^n + \sum_{i=0}^{n-1} p_i 2^{n-1-i}\) in non-adjacent form, i.e., \(f\in\{0, 1\}\) and \(p_i\in\{-1, 0, 1\}\) with no two adjacent digits nonzero; \(M\) is the number of \(p_i \neq 0\) (one phase shift with \(i\) controls each) and \(M_+\) the number of \(p_i = 1\) with \(i \geq 1\)

The following rules are for Adjoint(PCPhase), and they can be accessed with:

qp.decompose(gate_set=..., fixed_decomps={"Adjoint(PCPhase)": "<name>"})

adjoint_rotation

adjoint_rotation

Example: \(n=4\), \(d=3\)

Gate

Count

PCPhase

\(1\)

where phi changes sign

In short, this decomposition relies on decomposing the generator (see generator()) of the PCPhase gate into generators of multicontrolled PhaseShift gates, potentially complemented with (non-controlled) Pauli-X gates and/or a global phase. For example, for dim=13 on four qubits:

>>> op_13 = qp.PCPhase(1.23, dim=13, wires=[1, 2, 3, 4])
>>> print(qp.draw(op_13.decomposition)())
1: ─╭●─────────╭●───────────╭GlobalPhase(-1.23)─┤
2: ─╰Rϕ(-2.46)─├●───────────├GlobalPhase(-1.23)─┤
3: ────────────├○───────────├GlobalPhase(-1.23)─┤
4: ──X─────────╰Rϕ(2.46)──X─╰GlobalPhase(-1.23)─┤

In the following we provide a detailed example for illustration purposes.

Detailed example

Consider the projector-controlled phase gate on \(n=4\) qubits and with \(d=\texttt{dim}=3\), i.e,

>>> op_3 = qp.PCPhase(1.23, dim=3, wires=[0, 1, 2, 3])

It acts on \(N=2^n=16\)-dimensional vectors and is described by

\[\Pi(\phi) = \exp(i\phi G) = \exp(i\phi(2\Pi-\mathbb{I}_N)),\]

where \(G\) is a diagonal matrix with \(d=3\) ones, followed by \(2^n-d = 16 - 3=13\) negative ones. Accordingly, \(\Pi\) is diagonal with \(3\) ones and \(13\) zeros.

First, we implement the global phase generated by \(\mathbb{I}_N\) with a GlobalPhase gate with angle \(-\phi\). Then we decompose \(d\) into powers of two with positive or negative sign, via \(d=3=4-1 = 2^2-2^0\). This decomposition tells us that we can write the target gate with two (multi-)controlled phase shift gates. For this, we rewrite the projector \(\Pi\) according to the decomposition as

\[\begin{split}\Pi &= \text{diag}(1, 1, 1, 0, 0, \dots, 0)\\ &=\text{diag}(1, 1, 1, 1, 0, \dots, 0) -\text{diag}(0, 0, 0, 1, 0, \dots, 0)\end{split}\]

where \(0,\dots, 0\) indicates \(12\) zeros each time. How do we realize this projector decomposition on the gate level?

A singly-controlled phase shift gate applies a phase to a quarter of all computational basis states (the control filters by the state of one qubit, and the phase shift gate itself filters by the \(|1\rangle\) state of the target qubit, cutting the number of states we are acting on in half each time). For \(n=4\), this amounts to \(2^4/4=4\) states, which is exactly what we need for the first term above. To apply the phase to the first four states, \(|0000\rangle\), \(|0001\rangle\), \(|0010\rangle\), and \(|0011\rangle\), we want to “filter by” the first two qubits being in the \(|0\rangle\) state. For qubit \(0\), we do this by controlling on the \(|0\rangle\) state. For qubit \(1\), we pick it as the target of the controlled phase shift operation. Generically, this would make it act on the \(|1\rangle\) state, so we simply flip qubit \(1\) before and after the operation to apply the phase to the \(|0\rangle\) state instead. Thus, we conclude this first step by applying the gates qp.X(1), qp.ctrl(qp.PhaseShift(2 * phi, 1), control=[0], control_values=[0]), and qp.X(1).

Next, we implement the second term in the projector decomposition, applying a phase to a single computational basis state. This requires us to fully control a phase shift gate, i.e., we use the last qubit as target and the other three as controls (there is some freedom of choice here, but this is a convenient choice). We want to apply the phase to the state \(|3\rangle=|0011\rangle\). So the controls \(0\) and \(1\) are set to zero and the control \(2\) is set to one. As we want to effect the phase onto the \(|1\rangle\) state of qubit \(3\), we don’t need to flip the target bit as we did before. However, given the negative sign in the projector decomposition, we need to multiply the phase with \(-1\). Overall, we apply the gate qp.ctrl(qp.PhaseShift(-2 * phi, 3), control=[0, 1, 2], control_values=[0, 0, 1]), which concludes the decomposition, now reading:

>>> print(qp.draw(op_3.decomposition)())
0: ────╭○───────────╭○─────────╭GlobalPhase(1.23)─┤
1: ──X─╰Rϕ(2.46)──X─├○─────────├GlobalPhase(1.23)─┤
2: ─────────────────├●─────────├GlobalPhase(1.23)─┤
3: ─────────────────╰Rϕ(-2.46)─╰GlobalPhase(1.23)─┤

arg_specs

The expected types for the arguments of an operator.

arguments

Dictionary mapping argument names to their values.

arithmetic_depth

Arithmetic depth of the operator.

basis

The basis of the operator.

batch_size

Batch size of the operator if it is used with broadcasted parameters.

compilable_argnames

The names of arguments that are treated as compilable static arguments.

compilable_args

Dictionary mapping compilable argument names to their values.

data

Legacy Operator compatibility view of dynamic numerical arguments.

dim

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

dynamic_argnames

The names of arguments that are treated as dynamic.

dynamic_args

Dictionary mapping dynamic argument names to their values.

grad_method

Gradient computation method.

grad_recipe

Compute 'grad_recipe' lazily.

has_adjoint

has_decomposition

has_diagonalizing_gates

has_fixed_sig

Whether the expected signature of an operator is fixed.

has_generator

has_matrix

has_sparse_matrix

hybrid_argnames

The names of arguments that represent dynamic data wrapped in static structures (known as Pytrees).

hybrid_args

Dictionary mapping hybrid argument names to their values.

hyperparameters

Legacy Operator compatibility view of non-dynamic, non-wire constructor arguments.

is_fully_abstract

Whether this operator contains only abstract data.

is_verified_hermitian

This property determines if an operator is verified to be Hermitian.

name

Operator name.

ndim_params

Number of dimensions per trainable parameter that the operator depends on.

num_params

Number of trainable parameters that the operator depends on.

parameters

Legacy Operator compatibility view of dynamic numerical arguments as a list.

pauli_rep

A PauliSentence representation of the Operator, or None if it doesn't have one.

phi

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

static_argnames

The names of arguments that are treated as static.

static_args

Dictionary mapping static argument names to their values.

wire_argnames

The names of arguments corresponding to wires.

wire_args

Dictionary mapping wire argument names to their values.

wire_sizes

The expected number of wire labels for each wire argument.

wires

Wires that the operator acts on.

arg_specs = {'phi': AbstractArray((), float64, weak_type=True), 'wires': AbstractWires(-1)}

The expected types for the arguments of an operator. This attribute is optional—not setting it has no loss of functionality. If set, it can be used to perform automatic validation of an operators inputs during construction. Additionally, when defining decomposition rules for an operator, operator types with arg_specs that spans all the arguments with static types can be placed in the rules’ resources without needing to fully construct abstract operators.

Note

A type that is listed in ‘arg_specs’ says what an argument is allowed to be, not what it actually is. For example, if arg_specs contains Complex[-1, -1], the Operator can still be instantiated with a real float64 array, which will then be reported as complex even though it holds real data.

The decomposition graph goes by the reported type, so real and complex inputs will look like the same operator and share one rule. To let them decompose differently, leave the argument out of arg_specs and give each rule a register_condition that checks the type. For a concrete example see BasisRotation.

arguments

Dictionary mapping argument names to their values.

arithmetic_depth

Arithmetic depth of the operator.

basis

The basis of the operator.

batch_size

Batch size of the operator if it is used with broadcasted parameters.

The batch_size is determined based on ndim_params and the provided parameters for the operator. If (some of) the latter have an additional dimension, and this dimension has the same size for all parameters, its size is the batch size of the operator. If no parameter has an additional dimension, the batch size is None.

Returns:

Size of the parameter broadcasting dimension if present, else None.

Return type:

int or None

compilable_argnames = ('dim',)

The names of arguments that are treated as compilable static arguments. Compilable static arguments are a subset of static arguments—arguments whose concrete values are known when compiling the program. But, unlike static_argnames, they are lowered to the compiler intermediate representation, making their values visible to the compiler, which may be useful if the compiler needs to interact with such values. Such values may include numbers, strings, and lists, tuples, or dictionaries thereof. This feature is opt-in; if any static arguments are not guaranteed to be compilable, it is safer to place them in static_argnames.

Note

An operator can only specify static_argnames and hybrid_argnames, or compilable_argnames, but not both; if any static or hybrid arguments are not or cannot be lowered to the IR, then all static and hybrid arguments are assumed to not be lowerable.

compilable_args

Dictionary mapping compilable argument names to their values.

data

Legacy Operator compatibility view of dynamic numerical arguments.

dim

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

dynamic_argnames = ('phi',)

The names of arguments that are treated as dynamic. Dynamic arguments are numerical arguments whose concrete values may not be known at compile-time, such as rotation angles, matrices, etc., and may include trainable data. Additionally, dynamic arguments are the only ones used to infer batch_size, necessary for broadcasting support.

Inputs for these arguments must be scalars, arrays, or castable to arrays (e.g. multi- dimensional lists with homogenous shapes), and operator constructors will be responsible for “canonicalizing” them (such as casting a list input to an array). At compile-time, the concrete values of these arguments are assumed to be unknown—only their shapes and data types are known.

dynamic_args

Dictionary mapping dynamic argument names to their values.

grad_method

Gradient computation method.

  • 'A': analytic differentiation using the parameter-shift method.

  • 'F': finite difference numerical differentiation.

  • None: the operation may not be differentiated.

Default is 'F', or None if the Operation has zero parameters.

grad_recipe

Compute ‘grad_recipe’ lazily.

has_adjoint = True
has_decomposition = True
has_diagonalizing_gates = False
has_fixed_sig = False

Whether the expected signature of an operator is fixed. If True, then the operator’s signature will always be fully known. When defining decomposition rules for an operator, operator types with fixed signatures can be placed in the rules’ resources without needing to fully construct abstract operators. This is set automatically when arg_specs covers every dynamic and wire argument, there are no hybrid, static, or compilable arguments, and every declared type is fully fixed (no unknown array shapes or wire counts).

has_generator = True
has_matrix = True
has_sparse_matrix = False
hybrid_argnames = ()

The names of arguments that represent dynamic data wrapped in static structures (known as Pytrees). Names in this category must be disjoint from dynamic_argnames, static_argnames, and compilable_argnames, but may overlap with wire_argnames when those arguments contain nested structures of wires. Examples of hybrid arguments include collections of wires or dynamic arrays, operators, etc.

Note

An operator can only specify static_argnames and hybrid_argnames, or compilable_argnames, but not both; if any static or hybrid arguments are not or cannot be lowered to the IR, then all static and hybrid arguments are assumed to not be lowerable.

hybrid_args

Dictionary mapping hybrid argument names to their values.

hyperparameters

Legacy Operator compatibility view of non-dynamic, non-wire constructor arguments.

is_fully_abstract

Whether this operator contains only abstract data.

is_verified_hermitian

This property determines if an operator is verified to be Hermitian.

Note

This property provides a fast, non-exhaustive check used for internal optimizations. It relies on quick, provable shortcuts (e.g., operator properties) rather than a full, computationally expensive check.

For a definitive check, use the pennylane.is_hermitian() function. Please note that this comes with increased computational cost.

Returns:

The property will return True if the operator is guaranteed to be Hermitian and False if the check is inconclusive and the operator may or may not be Hermitian.

Return type:

bool

Consider this operator,

>>> op = (qp.X(0) @ qp.Y(0) - qp.X(0) @ qp.Z(0)) * 1j

In this case, Hermicity cannot be verified and leads to an inconclusive result:

>>> op.is_verified_hermitian # inconclusive
False

However, using pennylane.is_hermitian() will give the correct answer:

>>> qp.is_hermitian(op) # definitive
True
name

Operator name.

ndim_params = (0,)

Number of dimensions per trainable parameter that the operator depends on.

Type:

tuple[int]

num_params = 1

Number of trainable parameters that the operator depends on.

Type:

int

parameters

Legacy Operator compatibility view of dynamic numerical arguments as a list.

pauli_rep

A PauliSentence representation of the Operator, or None if it doesn’t have one.

phi

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

static_argnames = ()

The names of arguments that are treated as static. Static arguments are those whose concrete values are known when compiling the program. Arguments specified here are not lowered to a compiler intermediate representation (IR). Alternatively, if an argument is of a type that can be lowered, it can be moved to compilable_argnames.

Note

An operator can only specify static_argnames and hybrid_argnames, or compilable_argnames, but not both; if any static or hybrid arguments are not or cannot be lowered to the IR, then all static and hybrid arguments are assumed to not be lowerable.

static_args

Dictionary mapping static argument names to their values.

wire_argnames = ('wires',)

The names of arguments corresponding to wires. Values for these arguments are automatically wrapped in Wires objects by the Operator2 constructor. If an argument is expected to be a structure that wraps wires (known as pytrees), such as a list of wire registers, make sure to include its name in hybrid_argnames as well. Additionally, Operator2 does not descend into the pytree structure of such arguments, so subclasses must ensure every wire leaf inside a hybrid wire argument is already a Wires object before forwarding it to super().__init__.

The order in which names appear in wire_argnames determines the order in which their wires appear in op.wires (see Operator2.wires). For hybrid wire arguments, the contained Wires leaves are ordered by pytree traversal order. Wires contributed by arguments which are themselves Operator2 objects are appended after all wire_argnames wires. The special names "work_wires" and "work_wire" may be included in wire_argnames but their values are excluded from op.wires.

wire_args

Dictionary mapping wire argument names to their values.

wire_sizes = (None,)

The expected number of wire labels for each wire argument. If any wire arguments support an arbitrary size, None must be used. By default, all wire arguments are assumed to support arbitrary sizes. For hybrid wire arguments, the wire size must always be None. Specifying wire sizes allows for additional automatic validation to be implemented, but, specifying it is optional if such validation is not needed.

wires

Wires that the operator acts on.

By default, the returned Wires are collected from the operator’s arguments in the following order:

  1. For each name in wire_argnames (in declaration order):

    • If the name is not in hybrid_argnames, the canonical value of that argument is added.

    • If the name is in hybrid_argnames, every Wires leaf of the argument’s pytree is added in pytree traversal order.

  2. After all wire_argnames have been processed, for each name in hybrid_argnames that is not in wire_argnames, the wires of any Operator2 leaves inside that argument are appended to the end in pytree traversal order.

Duplicate wires are removed while preserving the first occurrence, so the final result is the ordered union of all wires above.

Note

By default, work wires are not included in op.wires. In particular, wire arguments named work_wires or work_wire are excluded.

Note

This property may be overridden by developers if the default behaviour is not desired, for reasons such as including work wires or changing the order of the wires.

Returns:

wires

Return type:

Wires

adjoint()

Computes the adjoint of the operator.

compute_decomposition(*args, **kwargs)

Representation of the operator as a product of other operators (static method).

compute_diagonalizing_gates(*args, **kwargs)

Sequence of gates that diagonalize the operator in the computational basis (static method).

compute_eigvals(phi, dim, wires)

Get the eigvals for the Pi-controlled phase unitary.

compute_matrix(phi, dim, wires)

Get the matrix representation of Pi-controlled phase unitary.

compute_sparse_matrix(*args[, format])

Representation of the operator as a sparse matrix in the computational basis (static method).

decomposition()

Representation of the operator as a product of other operators.

diagonalizing_gates()

Sequence of gates that diagonalize the operator in the computational basis.

eigvals()

Eigenvalues of the operator in the computational basis.

generator()

Generator of the PCPhase operator, which is in single-parameter-form.

label([decimals, base_label, cache])

The label of the operator when displayed in a circuit.

map_wires(wire_map)

Returns a new operator with its wires changed according to the given wire map.

matrix([wire_order])

Representation of the operator as a matrix in the computational basis.

pow(z)

Computes the operator raised to z.

queue([context])

Append the operator to the Operator queue.

simplify()

Simplifies the operator if possible.

sparse_matrix([wire_order, format])

Representation of the operator as a sparse matrix in the computational basis.

terms()

Representation of the operator as a linear combination of other operators.

adjoint()[source]

Computes the adjoint of the operator.

classmethod compute_decomposition(*args, **kwargs)

Representation of the operator as a product of other operators (static method).

\[O = O_1 O_2 \dots O_n.\]

Note

Operations making up the decomposition should be queued within the compute_decomposition method.

See also

decomposition().

Parameters:
  • *args (tuple) – Positional arguments of the operator

  • **kwargs (dict) – Keyword arguments of the operator

Returns:

decomposition of the operator

Return type:

list[Operator2]

static compute_diagonalizing_gates(*args, **kwargs)

Sequence of gates that diagonalize the operator in the computational basis (static method).

Given the eigendecomposition \(O = U \Sigma U^{\dagger}\) where \(\Sigma\) is a diagonal matrix containing the eigenvalues, the sequence of diagonalizing gates implements the unitary \(U^{\dagger}\).

The diagonalizing gates rotate the state into the eigenbasis of the operator.

Parameters:
  • *args (tuple) – Positional arguments of the operator

  • **kwargs (dict) – Keyword arguments of the operator

Returns:

list of diagonalizing gates

Return type:

list[.Operator2]

static compute_eigvals(phi, dim, wires)[source]

Get the eigvals for the Pi-controlled phase unitary.

static compute_matrix(phi, dim, wires)[source]

Get the matrix representation of Pi-controlled phase unitary.

static compute_sparse_matrix(*args, format='csr', **kwargs)

Representation of the operator as a sparse matrix in the computational basis (static method).

The canonical matrix is the textbook matrix representation that does not consider wires. Implicitly, this assumes that the wires of the operator correspond to the global wire order.

See also

sparse_matrix()

Parameters:
  • *args (tuple) – Positional arguments of the operator

  • format (str) – format of the returned scipy sparse matrix, for example ‘csr’

  • **kwargs (dict) – Keyword arguments of the operator

Returns:

sparse matrix representation

Return type:

scipy.sparse._csr.csr_matrix

decomposition()

Representation of the operator as a product of other operators.

\[O = O_1 O_2 \dots O_n\]

A DecompositionUndefinedError is raised if no representation by decomposition is defined.

Returns:

decomposition of the operator

Return type:

list[Operator2]

diagonalizing_gates()

Sequence of gates that diagonalize the operator in the computational basis.

Given the eigendecomposition \(O = U \Sigma U^{\dagger}\) where \(\Sigma\) is a diagonal matrix containing the eigenvalues, the sequence of diagonalizing gates implements the unitary \(U^{\dagger}\).

The diagonalizing gates rotate the state into the eigenbasis of the operator.

A DiagGatesUndefinedError is raised if no representation by decomposition is defined.

Returns:

a list of operators

Return type:

list[.Operator2] or None

eigvals()

Eigenvalues of the operator in the computational basis.

If diagonalizing_gates are specified and implement a unitary \(U^{\dagger}\), the operator can be reconstructed as

\[O = U \Sigma U^{\dagger},\]

where \(\Sigma\) is the diagonal matrix containing the eigenvalues.

Otherwise, no particular order for the eigenvalues is guaranteed.

Note

When eigenvalues are not explicitly defined, they are computed automatically from the matrix representation. Currently, this computation is not differentiable.

A EigvalsUndefinedError is raised if the eigenvalues have not been defined and cannot be inferred from the matrix representation.

Returns:

eigenvalues

Return type:

tensor_like

generator()[source]

Generator of the PCPhase operator, which is in single-parameter-form. The operator reads

\[\Pi(\phi) = e^{i\phi (2\Pi - \mathbb{I}_N)},\]

where \(\Pi\) is the projector onto the first :math`d` (dim) computational basis states and \(N=2^n\) is the Hilbert space dimension for \(n\) qubits.

Correspondingly, the generator is \(2\Pi - \mathbb{I}_N=\text{diag}(\underset{d\text{ times}}{\underbrace{1, \dots, 1}},\underset{(N-d)\text{ times}}{\underbrace{-1, \dots, -1}})\):

>>> qp.PCPhase(0.5, dim=3, wires=[0, 1]).generator()
Hermitian(array([[ 1,  0,  0,  0],
   [ 0,  1,  0,  0],
   [ 0,  0,  1,  0],
   [ 0,  0,  0, -1]]), wires=[0, 1])
label(decimals=None, base_label=None, cache=None)[source]

The label of the operator when displayed in a circuit.

map_wires(wire_map)

Returns a new operator with its wires changed according to the given wire map.

Parameters:

wire_map (dict) – dictionary containing the old wires as keys and the new wires as values

Returns:

new operator

Return type:

.Operator2

matrix(wire_order=None)

Representation of the operator as a matrix in the computational basis.

If wire_order is provided, the numerical representation considers the position of the operator’s wires in the global wire order. Otherwise, the wire order defaults to the operator’s wires.

If the matrix depends on trainable parameters, the result will be cast in the same autodifferentiation framework as the parameters.

A MatrixUndefinedError is raised if the matrix representation has not been defined.

See also

compute_matrix()

Parameters:

wire_order (Iterable) – global wire order, must contain all wire labels from the operator’s wires

Returns:

matrix representation

Return type:

tensor_like

pow(z)[source]

Computes the operator raised to z.

queue(context=<class 'pennylane.core.queuing.QueuingManager'>)

Append the operator to the Operator queue.

simplify()[source]

Simplifies the operator if possible.

sparse_matrix(wire_order=None, format='csr')

Representation of the operator as a sparse matrix in the computational basis.

If wire_order is provided, the numerical representation considers the position of the operator’s wires in the global wire order. Otherwise, the wire order defaults to the operator’s wires.

A SparseMatrixUndefinedError is raised if the sparse matrix representation has not been defined.

Parameters:
  • wire_order (Iterable) – global wire order, must contain all wire labels from the operator’s wires

  • format (str) – format of the returned scipy sparse matrix, for example ‘csr’

Returns:

sparse matrix representation

Return type:

scipy.sparse._csr.csr_matrix

terms()

Representation of the operator as a linear combination of other operators.

\[O = \sum_i c_i O_i\]

A TermsUndefinedError is raised if no representation by terms is defined.

Returns:

list of coefficients \(c_i\) and list of operations \(O_i\)

Return type:

tuple[list[tensor_like or float], list[.Operator2]]

Contents

Using PennyLane

Release news

Development

API

Internals