qml.ops.qubit.attributes.Attribute

class Attribute[source]

Bases: set

Class to represent a set of operators with a certain attribute.

Example

Suppose we would like to store a list of which qubit operations are Pauli operators. We can create a new Attribute, pauli_ops, like so, listing which operations satisfy this property.

>>> pauli_ops = Attribute(["PauliX", "PauliZ"])

We can check either a string or an Operation for inclusion in this set:

>>> qml.X(0) in pauli_ops
True
>>> "Hadamard" in pauli_ops
False

We can also dynamically add operators to the sets at runtime, by passing either a string, an operation class, or an operation itself. This is useful for adding custom operations to the attributes such as composable_rotations and self_inverses that are used in compilation transforms.

>>> pauli_ops.add("PauliY")
>>> pauli_ops
["PauliX", "PauliY", "PauliZ"]

add(obj)

Add an Operator to an attribute.

clear

Remove all elements from this set.

copy

Return a shallow copy of a set.

difference

Return the difference of two or more sets as a new set.

difference_update

Remove all elements of another set from this set.

discard

Remove an element from a set if it is a member.

intersection

Return the intersection of two sets as a new set.

intersection_update

Update a set with the intersection of itself and another.

isdisjoint

Return True if two sets have a null intersection.

issubset

Report whether another set contains this set.

issuperset

Report whether this set contains another set.

pop

Remove and return an arbitrary set element.

remove

Remove an element from a set; it must be a member.

symmetric_difference

Return the symmetric difference of two sets as a new set.

symmetric_difference_update

Update a set with the symmetric difference of itself and another.

union

Return the union of sets as a new set.

update

Update a set with the union of itself and others.

add(obj)[source]

Add an Operator to an attribute.

clear()

Remove all elements from this set.

copy()

Return a shallow copy of a set.

difference()

Return the difference of two or more sets as a new set.

(i.e. all elements that are in this set but not the others.)

difference_update()

Remove all elements of another set from this set.

discard()

Remove an element from a set if it is a member.

If the element is not a member, do nothing.

intersection()

Return the intersection of two sets as a new set.

(i.e. all elements that are in both sets.)

intersection_update()

Update a set with the intersection of itself and another.

isdisjoint()

Return True if two sets have a null intersection.

issubset()

Report whether another set contains this set.

issuperset()

Report whether this set contains another set.

pop()

Remove and return an arbitrary set element. Raises KeyError if the set is empty.

remove()

Remove an element from a set; it must be a member.

If the element is not a member, raise a KeyError.

symmetric_difference()

Return the symmetric difference of two sets as a new set.

(i.e. all elements that are in exactly one of the sets.)

symmetric_difference_update()

Update a set with the symmetric difference of itself and another.

union()

Return the union of sets as a new set.

(i.e. all elements that are in either set.)

update()

Update a set with the union of itself and others.