braket.circuits.observables module

class braket.circuits.observables.H[source]

Bases: StandardObservable

Hadamard operation as an observable.

Examples: >>> Observable.H()

to_matrix() ndarray[source]

Returns a matrix representation of the quantum operator.

Parameters:
  • *args (Any) – Not Implemented.

  • **kwargs (Any) – Not Implemented.

Raises:

NotImplementError – Not Implemented.

Returns:

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates: tuple[Gate, ...]

Returns the basis rotation gates for this observable.

Returns:

tuple[Gate, …] – The basis rotation gates for this observable.

class braket.circuits.observables.I[source]

Bases: Observable

Identity operation as an observable.

Examples: >>> Observable.I()

to_matrix() ndarray[source]

Returns a matrix representation of the quantum operator.

Parameters:
  • *args (Any) – Not Implemented.

  • **kwargs (Any) – Not Implemented.

Raises:

NotImplementError – Not Implemented.

Returns:

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates: tuple[Gate, ...]

Returns the basis rotation gates for this observable.

Returns:

tuple[Gate, …] – The basis rotation gates for this observable.

property eigenvalues: ndarray

Returns the eigenvalues of this observable.

Returns:

np.ndarray – The eigenvalues of this observable.

eigenvalue(index: int) float[source]

Returns the eigenvalue of this observable at the given index.

The eigenvalues are ordered by their corresponding computational basis state after diagonalization.

Parameters:

index (int) – The index of the desired eigenvalue

Returns:

float – The index th eigenvalue of the observable.

class braket.circuits.observables.X[source]

Bases: StandardObservable

Pauli-X operation as an observable.

Examples: >>> Observable.X()

to_matrix() ndarray[source]

Returns a matrix representation of the quantum operator.

Parameters:
  • *args (Any) – Not Implemented.

  • **kwargs (Any) – Not Implemented.

Raises:

NotImplementError – Not Implemented.

Returns:

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates: tuple[Gate, ...]

Returns the basis rotation gates for this observable.

Returns:

tuple[Gate, …] – The basis rotation gates for this observable.

class braket.circuits.observables.Y[source]

Bases: StandardObservable

Pauli-Y operation as an observable.

Examples: >>> Observable.Y()

to_matrix() ndarray[source]

Returns a matrix representation of the quantum operator.

Parameters:
  • *args (Any) – Not Implemented.

  • **kwargs (Any) – Not Implemented.

Raises:

NotImplementError – Not Implemented.

Returns:

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates: tuple[Gate, ...]

Returns the basis rotation gates for this observable.

Returns:

tuple[Gate, …] – The basis rotation gates for this observable.

class braket.circuits.observables.Z[source]

Bases: StandardObservable

Pauli-Z operation as an observable.

Examples: >>> Observable.Z()

to_matrix() ndarray[source]

Returns a matrix representation of the quantum operator.

Parameters:
  • *args (Any) – Not Implemented.

  • **kwargs (Any) – Not Implemented.

Raises:

NotImplementError – Not Implemented.

Returns:

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates: tuple[Gate, ...]

Returns the basis rotation gates for this observable.

Returns:

tuple[Gate, …] – The basis rotation gates for this observable.

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

Bases: Observable

Tensor product of observables

Initializes a TensorProduct.

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: You must provide the list of observables for the tensor product to be evaluated in the order that you want the tensor product to be calculated. For TensorProduct(observables=[ob1, ob2, ob3]), the tensor product’s matrix is the result of the tensor product of ob1, ob2, ob3, or np.kron(np.kron(ob1.to_matrix(), ob2.to_matrix()), ob3.to_matrix()).

property ascii_symbols: tuple[str, ...]

Returns the ascii symbols for the quantum operator.

Type:

tuple[str, …]

property factors: tuple[Observable, ...]

The observables that comprise this tensor product.

Type:

tuple[Observable]

to_matrix() ndarray[source]

Returns a matrix representation of the quantum operator.

Parameters:
  • *args (Any) – Not Implemented.

  • **kwargs (Any) – Not Implemented.

Raises:

NotImplementError – Not Implemented.

Returns:

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates: tuple[Gate, ...]

Returns the basis rotation gates for this observable.

Returns:

tuple[Gate, …] – The basis rotation gates for this observable.

property eigenvalues: ndarray

Returns the eigenvalues of this observable.

Returns:

np.ndarray – The eigenvalues of this observable.

eigenvalue(index: int) float[source]

Returns the eigenvalue of this observable at the given index.

The eigenvalues are ordered by their corresponding computational basis state after diagonalization.

Parameters:

index (int) – The index of the desired eigenvalue

Returns:

float – The index th eigenvalue of the observable.

class braket.circuits.observables.Sum(observables: list[Observable], display_name: str = 'Hamiltonian')[source]

Bases: Observable

Sum of observables

Inits a Sum.

Parameters:
  • observables (list[Observable]) – List of observables for Sum

  • display_name (str) – Name to use for an instance of this Sum observable for circuit diagrams. Defaults to Hamiltonian.

Examples

>>> t1 = -3 * Observable.Y() + 2 * Observable.X()
Sum(X('qubit_count': 1), Y('qubit_count': 1))
>>> t1.summands
(X('qubit_count': 1), Y('qubit_count': 1))
property summands: tuple[Observable, ...]

The observables that comprise this sum.

Type:

tuple[Observable]

to_matrix() ndarray[source]

Returns a matrix representation of the quantum operator.

Parameters:
  • *args (Any) – Not Implemented.

  • **kwargs (Any) – Not Implemented.

Raises:

NotImplementError – Not Implemented.

Returns:

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates: tuple[Gate, ...]

Returns the basis rotation gates for this observable.

Returns:

tuple[Gate, …] – The basis rotation gates for this observable.

property eigenvalues: ndarray

Returns the eigenvalues of this observable.

Returns:

np.ndarray – The eigenvalues of this observable.

eigenvalue(index: int) float[source]

Returns the eigenvalue of this observable at the given index.

The eigenvalues are ordered by their corresponding computational basis state after diagonalization.

Parameters:

index (int) – The index of the desired eigenvalue

Returns:

float – The index th eigenvalue of the observable.

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

Bases: Observable

Hermitian matrix as an observable.

Inits a Hermitian.

Parameters:
  • matrix (np.ndarray) – Hermitian matrix that defines the observable.

  • display_name (str) – Name to use 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 that is not a positive power of 2, or is not Hermitian.

Examples

>>> Observable.Hermitian(matrix=np.array([[0, 1],[1, 0]]))
to_matrix() ndarray[source]

Returns a matrix representation of the quantum operator.

Parameters:
  • *args (Any) – Not Implemented.

  • **kwargs (Any) – Not Implemented.

Raises:

NotImplementError – Not Implemented.

Returns:

np.ndarray – A matrix representation of the quantum operator

property basis_rotation_gates: tuple[Gate, ...]

Returns the basis rotation gates for this observable.

Returns:

tuple[Gate, …] – The basis rotation gates for this observable.

property eigenvalues: ndarray

Returns the eigenvalues of this observable.

Returns:

np.ndarray – The eigenvalues of this observable.

eigenvalue(index: int) float[source]

Returns the eigenvalue of this observable at the given index.

The eigenvalues are ordered by their corresponding computational basis state after diagonalization.

Parameters:

index (int) – The index of the desired eigenvalue

Returns:

float – The index th eigenvalue of the observable.

braket.circuits.observables.observable_from_ir(ir_observable: list[str | list[list[list[float]]]]) 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