braket.circuits.observable module¶
-
class
braket.circuits.observable.
Observable
(qubit_count: int, ascii_symbols: Sequence[str])[source]¶ Bases:
braket.circuits.quantum_operator.QuantumOperator
Class
Observable
to represent a quantum observable.Objects of this type can be used as input to
ResultType.Sample
,ResultType.Variance
,ResultType.Expectation
to specify the measurement basis.- Parameters
qubit_count (int) – Number of qubits this quantum operator interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the quantum operator. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises
ValueError –
qubit_count
is less than 1,ascii_symbols
are None, orascii_symbols
length !=qubit_count
-
to_ir
() → List[Union[str, List[List[List[float]]]]][source]¶ List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable
-
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
-
classmethod
register_observable
(observable: braket.circuits.observable.Observable) → None[source]¶ Register an observable implementation by adding it into the Observable class.
- Parameters
observable (Observable) – Observable class to register.
-
class
H
¶ Bases:
braket.circuits.observable.StandardObservable
Hadamard operation as an observable.
Examples
>>> Observable.I()
-
property
basis_rotation_gates
¶ Returns the basis rotation gates for this observable.
- Type
Tuple[Gate]
-
to_ir
() → List[str]¶ List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable
-
to_matrix
() → numpy.ndarray¶ Returns a matrix representation of the quantum operator
- Returns
np.ndarray – A matrix representation of the quantum operator
-
property
-
class
Hermitian
(matrix: numpy.ndarray, display_name: str = 'Hermitian')¶ 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]]))
-
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
-
to_ir
() → List[List[List[List[float]]]]¶ List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable
-
to_matrix
() → numpy.ndarray¶ Returns a matrix representation of the quantum operator
- Returns
np.ndarray – A matrix representation of the quantum operator
-
class
I
¶ Bases:
braket.circuits.observable.Observable
Identity operation as an observable.
Examples
>>> Observable.I()
-
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
-
to_ir
() → List[str]¶ List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable
-
to_matrix
() → numpy.ndarray¶ Returns a matrix representation of the quantum operator
- Returns
np.ndarray – A matrix representation of the quantum operator
-
property
-
class
TensorProduct
(observables: List[braket.circuits.observable.Observable])¶ 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.observables (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 ofob1
,ob2
,ob3
, ornp.kron(np.kron(ob1.to_matrix(), ob2.to_matrix()), ob3.to_matrix())
-
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
-
property
observables
¶ observables part of tensor product
- Type
Tuple[Observable]
-
to_ir
() → List[str]¶ List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable
-
to_matrix
() → numpy.ndarray¶ Returns a matrix representation of the quantum operator
- Returns
np.ndarray – A matrix representation of the quantum operator
-
class
X
¶ Bases:
braket.circuits.observable.StandardObservable
Pauli-X operation as an observable.
Examples
>>> Observable.X()
-
property
basis_rotation_gates
¶ Returns the basis rotation gates for this observable.
- Type
Tuple[Gate]
-
to_ir
() → List[str]¶ List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable
-
to_matrix
() → numpy.ndarray¶ Returns a matrix representation of the quantum operator
- Returns
np.ndarray – A matrix representation of the quantum operator
-
property
-
class
Y
¶ Bases:
braket.circuits.observable.StandardObservable
Pauli-Y operation as an observable.
Examples
>>> Observable.Y()
-
property
basis_rotation_gates
¶ Returns the basis rotation gates for this observable.
- Type
Tuple[Gate]
-
to_ir
() → List[str]¶ List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable
-
to_matrix
() → numpy.ndarray¶ Returns a matrix representation of the quantum operator
- Returns
np.ndarray – A matrix representation of the quantum operator
-
property
-
class
Z
¶ Bases:
braket.circuits.observable.StandardObservable
Pauli-Z operation as an observable.
Examples
>>> Observable.Z()
-
property
basis_rotation_gates
¶ Returns the basis rotation gates for this observable.
- Type
Tuple[Gate]
-
to_ir
() → List[str]¶ List[Union[str, List[List[List[float]]]]]: Returns the IR representation for the observable
-
to_matrix
() → numpy.ndarray¶ Returns a matrix representation of the quantum operator
- Returns
np.ndarray – A matrix representation of the quantum operator
-
property
-
class
braket.circuits.observable.
StandardObservable
(qubit_count: int, ascii_symbols: Sequence[str])[source]¶ Bases:
braket.circuits.observable.Observable
Class
StandardObservable
to represent a standard quantum observable with eigenvalues of +/-1, each with a multiplicity of 1.- Parameters
qubit_count (int) – Number of qubits this quantum operator interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the quantum operator. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises
ValueError –
qubit_count
is less than 1,ascii_symbols
are None, orascii_symbols
length !=qubit_count
-
property
eigenvalues
¶ Returns the eigenvalues of this observable.
- Type
np.ndarray