braket.circuits.observables module

class braket.circuits.observables.H[source]

Bases: braket.circuits.observable.StandardObservable

Hadamard operation as an observable.

Examples

>>> Observable.I()
to_ir() → List[str][source]

List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable

to_matrix() → numpy.ndarray[source]

Returns a matrix representation of the quantum operator

Returns

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates

Returns the basis rotation gates for this observable.

Type

Tuple[Gate]

class braket.circuits.observables.I[source]

Bases: braket.circuits.observable.Observable

Identity operation as an observable.

Examples

>>> Observable.I()
to_ir() → List[str][source]

List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable

to_matrix() → numpy.ndarray[source]

Returns a matrix representation of the quantum operator

Returns

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates

Returns the basis rotation gates for this observable.

Type

Tuple[Gate]

property eigenvalues

Returns the eigenvalues of this observable.

Type

np.ndarray

class braket.circuits.observables.X[source]

Bases: braket.circuits.observable.StandardObservable

Pauli-X operation as an observable.

Examples

>>> Observable.X()
to_ir() → List[str][source]

List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable

to_matrix() → numpy.ndarray[source]

Returns a matrix representation of the quantum operator

Returns

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates

Returns the basis rotation gates for this observable.

Type

Tuple[Gate]

class braket.circuits.observables.Y[source]

Bases: braket.circuits.observable.StandardObservable

Pauli-Y operation as an observable.

Examples

>>> Observable.Y()
to_ir() → List[str][source]

List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable

to_matrix() → numpy.ndarray[source]

Returns a matrix representation of the quantum operator

Returns

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates

Returns the basis rotation gates for this observable.

Type

Tuple[Gate]

class braket.circuits.observables.Z[source]

Bases: braket.circuits.observable.StandardObservable

Pauli-Z operation as an observable.

Examples

>>> Observable.Z()
to_ir() → List[str][source]

List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable

to_matrix() → numpy.ndarray[source]

Returns a matrix representation of the quantum operator

Returns

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates

Returns the basis rotation gates for this observable.

Type

Tuple[Gate]

class braket.circuits.observables.TensorProduct(observables: List[braket.circuits.observable.Observable])[source]

Bases: braket.circuits.observable.Observable

Tensor product of observables

Parameters

observables (List[Observable]) – List of observables for tensor product

Examples

>>> t1 = Observable.Y() @ Observable.X()
>>> t1.to_matrix()
array([[0.+0.j, 0.+0.j, 0.-0.j, 0.-1.j],
[0.+0.j, 0.+0.j, 0.-1.j, 0.-0.j],
[0.+0.j, 0.+1.j, 0.+0.j, 0.+0.j],
[0.+1.j, 0.+0.j, 0.+0.j, 0.+0.j]])
>>> t2 = Observable.Z() @ t1
>>> t2.factors
(Z('qubit_count': 1), Y('qubit_count': 1), X('qubit_count': 1))

Note: list of observables for tensor product must be given in the desired order that the tensor product will be calculated. For TensorProduct(observables=[ob1, ob2, ob3]), the tensor product’s matrix will be the result of the tensor product of ob1, ob2, ob3, or np.kron(np.kron(ob1.to_matrix(), ob2.to_matrix()), ob3.to_matrix())

to_ir() → List[str][source]

List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable

property factors

The observables that make up this tensor product

Type

Tuple[Observable]

to_matrix() → numpy.ndarray[source]

Returns a matrix representation of the quantum operator

Returns

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates

Returns the basis rotation gates for this observable.

Type

Tuple[Gate]

property eigenvalues

Returns the eigenvalues of this observable.

Type

np.ndarray

class braket.circuits.observables.Hermitian(matrix: numpy.ndarray, display_name: str = 'Hermitian')[source]

Bases: braket.circuits.observable.Observable

Hermitian matrix as an observable.

Parameters
  • matrix (numpy.ndarray) – Hermitian matrix which defines the observable.

  • display_name (str) – Name to be used for an instance of this Hermitian matrix observable for circuit diagrams. Defaults to Hermitian.

Raises

ValueError – If matrix is not a two-dimensional square matrix, or has a dimension length which is not a positive exponent of 2, or is non-hermitian.

Example

>>> Observable.Hermitian(matrix=np.array([[0, 1],[1, 0]]))
to_ir() → List[List[List[List[float]]]][source]

List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable

to_matrix() → numpy.ndarray[source]

Returns a matrix representation of the quantum operator

Returns

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates

Returns the basis rotation gates for this observable.

Type

Tuple[Gate]

property eigenvalues

Returns the eigenvalues of this observable.

Type

np.ndarray

braket.circuits.observables.observable_from_ir(ir_observable: List[Union[str, List[List[List[float]]]]])braket.circuits.observable.Observable[source]

Create an observable from the IR observable list. This can be a tensor product of observables or a single observable.

Parameters

ir_observable (List[Union[str, List[List[List[float]]]]]) – observable as defined in IR

Returns

Observable – observable object