Observables
- class braket.circuits.observables.H(target=None)[source]
Bases:
StandardObservableHadamard operation as an observable.
- Parameters:
target (QubitInput | None)
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=None)[source]
Bases:
ObservableIdentity operation as an observable.
- Parameters:
target (QubitInput | None)
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()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- property basis_rotation_gates: tuple[Gate, ...]
The basis rotation gates for this observable.
- Type:
tuple[Gate, …]
- property euler_angles: dict[str, float]
A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- Type:
dict[str, float]
- static get_euler_angles(targets)[source]
Get the ZXZ Euler angle mapping of this observable for the given qubit.
- Parameters:
targets (QubitSetInput) – The target qubits; this is used for the parameter names in the output mapping.
- Return type:
dict[str, float]
- Returns:
dict[str, float] – A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- property eigenvalues: ndarray
Returns the eigenvalues of this observable.
- Returns:
np.ndarray – The eigenvalues of this observable.
- eigenvalue(index)[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
- Return type:
float- Returns:
float – The
indexth eigenvalue of the observable.
- class braket.circuits.observables.X(target=None)[source]
Bases:
StandardObservablePauli-X operation as an observable.
- Parameters:
target (QubitInput | None)
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()
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- property basis_rotation_gates: tuple[Gate, ...]
The basis rotation gates for this observable.
- Type:
tuple[Gate, …]
- property euler_angles: dict[str, float]
A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- Type:
dict[str, float]
- static get_euler_angles(targets)[source]
Get the ZXZ Euler angle mapping of this observable for the given qubit.
- Parameters:
targets (QubitSetInput) – The target qubits; this is used for the parameter names in the output mapping.
- Return type:
dict[str, float]
- Returns:
dict[str, float] – A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- class braket.circuits.observables.Y(target=None)[source]
Bases:
StandardObservablePauli-Y operation as an observable.
- Parameters:
target (QubitInput | None)
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()
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- property basis_rotation_gates: tuple[Gate, ...]
The basis rotation gates for this observable.
- Type:
tuple[Gate, …]
- property euler_angles: dict[str, float]
A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- Type:
dict[str, float]
- static get_euler_angles(targets)[source]
Get the ZXZ Euler angle mapping of this observable for the given qubit.
- Parameters:
targets (QubitSetInput) – The target qubits; this is used for the parameter names in the output mapping.
- Return type:
dict[str, float]
- Returns:
dict[str, float] – A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- class braket.circuits.observables.Z(target=None)[source]
Bases:
StandardObservablePauli-Z operation as an observable.
- Parameters:
target (QubitInput | None)
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()
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- property basis_rotation_gates: tuple[Gate, ...]
The basis rotation gates for this observable.
- Type:
tuple[Gate, …]
- property euler_angles: dict[str, float]
A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- Type:
dict[str, float]
- static get_euler_angles(targets)[source]
Get the ZXZ Euler angle mapping of this observable for the given qubit.
- Parameters:
targets (QubitSetInput) – The target qubits; this is used for the parameter names in the output mapping.
- Return type:
dict[str, float]
- Returns:
dict[str, float] – A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- class braket.circuits.observables.TensorProduct(observables)[source]
Bases:
ObservableTensor product of observables
- Parameters:
observables (
list[Observable])
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()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- 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 euler_angles: dict[str, float]
A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- Type:
dict[str, float]
- get_euler_angles(targets)[source]
Get the ZXZ Euler angle mapping of this observable for the given qubit.
- Parameters:
targets (QubitSetInput) – The target qubits; this is used for the parameter names in the output mapping.
- Return type:
dict[str, float]
- Returns:
dict[str, float] – A mapping of standardized free parameter name to ZXZ Euler angle value that diagonalizes this observable.
- property eigenvalues: ndarray
Returns the eigenvalues of this observable.
- Returns:
np.ndarray – The eigenvalues of this observable.
- eigenvalue(index)[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
- Return type:
float- Returns:
float – The
indexth eigenvalue of the observable.
- class braket.circuits.observables.Sum(observables, display_name='Hamiltonian')[source]
Bases:
ObservableSum of observables
- Parameters:
observables (
list[Observable])display_name (
str)
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()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- property basis_rotation_gates: tuple[Gate, ...]
The basis rotation gates for this observable.
- Type:
tuple[Gate, …]
- property eigenvalues: ndarray
The eigenvalues of this observable.
- Type:
np.ndarray
- eigenvalue(index)[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
- Return type:
float- Returns:
float – The
indexth eigenvalue of the observable.
- class braket.circuits.observables.Hermitian(matrix, display_name='Hermitian', targets=None)[source]
Bases:
ObservableHermitian matrix as an observable.
- Parameters:
matrix (np.ndarray)
display_name (str)
targets (QubitSetInput | None)
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
matrixis 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()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- property basis_rotation_gates: tuple[Gate, ...]
The basis rotation gates for this observable.
- Type:
tuple[Gate, …]
- property eigenvalues: ndarray
Returns the eigenvalues of this observable.
- Returns:
np.ndarray – The eigenvalues of this observable.
- eigenvalue(index)[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
- Return type:
float- Returns:
float – The
indexth eigenvalue of the observable.
- braket.circuits.observables.observable_from_ir(ir_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[str | list[list[list[float]]]]) – observable as defined in IR
- Return type:
- Returns:
Observable – observable object