braket.circuits.observables module
- class braket.circuits.observables.H(target: QubitInput | None = None)[source]
Bases:
StandardObservable
Hadamard operation as an observable.
Initializes Hadamard observable.
- Parameters:
target (QubitInput | None) – The target qubit to measure the observable on. If not provided, this needs to be provided from the enclosing result type. Default:
None
.
Examples
>>> observables.H(0) >>> observables.H()
- class braket.circuits.observables.I(target: QubitInput | None = None)[source]
Bases:
Observable
Identity operation as an observable.
Initializes Identity observable.
- Parameters:
target (QubitInput | None) – The target qubit to measure the observable on. If not provided, this needs to be provided from the enclosing result type. Default:
None
.
Examples
>>> observables.I(0) >>> observables.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(target: QubitInput | None = None)[source]
Bases:
StandardObservable
Pauli-X operation as an observable.
Initializes Pauli-X observable.
- Parameters:
target (QubitInput | None) – The target qubit to measure the observable on. If not provided, this needs to be provided from the enclosing result type. Default:
None
.
Examples
>>> observables.X(0) >>> observables.X()
- class braket.circuits.observables.Y(target: QubitInput | None = None)[source]
Bases:
StandardObservable
Pauli-Y operation as an observable.
Initializes Pauli-Y observable.
- Parameters:
target (QubitInput | None) – The target qubit to measure the observable on. If not provided, this needs to be provided from the enclosing result type. Default:
None
.
Examples
>>> observables.Y(0) >>> observables.Y()
- class braket.circuits.observables.Z(target: QubitInput | None = None)[source]
Bases:
StandardObservable
Pauli-Z operation as an observable.
Initializes Pauli-Z observable.
- Parameters:
target (QubitInput | None) – The target qubit to measure the observable on. If not provided, this needs to be provided from the enclosing result type. Default:
None
.
Examples
>>> observables.Z(0) >>> observables.Z()
- 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(0) @ Observable.X(1) >>> 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(3) @ 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 ofob1
,ob2
,ob3
, ornp.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(0) + 2 * Observable.X(0) 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: np.ndarray, display_name: str = 'Hermitian', targets: QubitSetInput | None = None)[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
.targets (QubitSetInput | None) – The target qubits to measure the observable on. If not provided, this needs to be provided from the enclosing result type. Default:
None
.
- Raises:
ValueError – If
matrix
is not a two-dimensional square matrix, is not Hermitian, or has a dimension length that is either not a positive power of 2 or, if targets is supplied, doesn’t match the size of targets.
Examples
>>> observables.Hermitian(matrix=np.array([[0, 1], [1, 0]]), targets=[0]) >>> observables.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