braket.default_simulator.observables module
- class braket.default_simulator.observables.Identity(targets: list[int] | None = None)[source]
Bases:
Observable
Identity observable
Note
This observable refers to the same mathematical object as the gate operation of the same name, but is meant to be used differently; the observable is viewed as a Hermitian operator to be measured, while the gate is viewed as a unitary operator to evolve the state of the system.
- property targets: tuple[int, ...]
The indices of the qubits the operation applies to.
Note: For an index to be a target of an observable, the observable must have a nontrivial (i.e. non-identity) action on that index. For example, a tensor product observable with a Z factor on qubit j acts trivially on j, so j would not be a target. This does not apply to gate operations.
- Type:
tuple[int, …]
- property measured_qubits
The indices of the qubits that are measured for this observable.
Unlike
targets
, this includes indices on which the observable acts trivially. For example, a tensor product observable made entirely of n Z factors will have n measured qubits.- Type:
tuple[int, …]
- property eigenvalues: ndarray
The eigenvalues of the observable ordered by computational basis state.
- Type:
np.ndarray
- apply(state: ndarray) ndarray [source]
Applies this observable to the given state.
- Parameters:
state (np.ndarray) – The state to apply the observable to.
- Returns:
np.ndarray – The state after the observable has been applied.
- fix_qubit(qubit: int) Observable [source]
Creates a copy of it acting on the given qubit.
Only defined for observables that act on 1 qubit.
- Parameters:
qubit (int) – The target qubit of the new observable.
- Returns:
Observable – A copy of this observable, acting on the new qubit.
- diagonalizing_gates(num_qubits: int | None = None) tuple[GateOperation, ...] [source]
The gates that diagonalize the observable in the computational basis.
- Parameters:
num_qubits (int, optional) – The number of qubits the observable acts on. Only used if no target is specified, in which case a gate is created for each target qubit. This only makes sense for single-qubit observables.
- Returns:
tuple[GateOperation, …] – The gates that diagonalize the observable in the computational basis, if it is not already in the computational basis. If there is no explicit target, this method returns a tuple of gates acting on every qubit.
- class braket.default_simulator.observables.Hadamard(targets: list[int] | None = None)[source]
Bases:
_InvolutoryMatrixObservable
Hadamard observable
Note
This observable refers to the same mathematical object as the gate operation of the same name, but is meant to be used differently; the observable is viewed as a Hermitian operator to be measured, while the gate is viewed as a unitary operator to evolve the state of the system.
- property is_standard: bool
Whether the observable is Pauli-like, that is, has eigenvalues of \(\pm 1\).
Examples include the Pauli and Hadamard observables.
- Type:
bool
- property eigenvalues: ndarray
The eigenvalues of the observable ordered by computational basis state.
- Type:
np.ndarray
- fix_qubit(qubit: int) Observable [source]
Creates a copy of it acting on the given qubit.
Only defined for observables that act on 1 qubit.
- Parameters:
qubit (int) – The target qubit of the new observable.
- Returns:
Observable – A copy of this observable, acting on the new qubit.
- diagonalizing_gates(num_qubits: int | None = None) tuple[GateOperation, ...] [source]
The gates that diagonalize the observable in the computational basis.
- Parameters:
num_qubits (int, optional) – The number of qubits the observable acts on. Only used if no target is specified, in which case a gate is created for each target qubit. This only makes sense for single-qubit observables.
- Returns:
tuple[GateOperation, …] – The gates that diagonalize the observable in the computational basis, if it is not already in the computational basis. If there is no explicit target, this method returns a tuple of gates acting on every qubit.
- class braket.default_simulator.observables.PauliX(targets: list[int] | None = None)[source]
Bases:
_InvolutoryMatrixObservable
Pauli-X observable
Note
This observable refers to the same mathematical object as the gate operation of the same name, but is meant to be used differently; the observable is viewed as a Hermitian operator to be measured, while the gate is viewed as a unitary operator to evolve the state of the system.
- property is_standard: bool
Whether the observable is Pauli-like, that is, has eigenvalues of \(\pm 1\).
Examples include the Pauli and Hadamard observables.
- Type:
bool
- property eigenvalues: ndarray
The eigenvalues of the observable ordered by computational basis state.
- Type:
np.ndarray
- fix_qubit(qubit: int) Observable [source]
Creates a copy of it acting on the given qubit.
Only defined for observables that act on 1 qubit.
- Parameters:
qubit (int) – The target qubit of the new observable.
- Returns:
Observable – A copy of this observable, acting on the new qubit.
- diagonalizing_gates(num_qubits: int | None = None) tuple[GateOperation, ...] [source]
The gates that diagonalize the observable in the computational basis.
- Parameters:
num_qubits (int, optional) – The number of qubits the observable acts on. Only used if no target is specified, in which case a gate is created for each target qubit. This only makes sense for single-qubit observables.
- Returns:
tuple[GateOperation, …] – The gates that diagonalize the observable in the computational basis, if it is not already in the computational basis. If there is no explicit target, this method returns a tuple of gates acting on every qubit.
- class braket.default_simulator.observables.PauliY(targets: list[int] | None = None)[source]
Bases:
_InvolutoryMatrixObservable
Pauli-Y observable
Note
This observable refers to the same mathematical object as the gate operation of the same name, but is meant to be used differently; the observable is viewed as a Hermitian operator to be measured, while the gate is viewed as a unitary operator to evolve the state of the system.
- property is_standard: bool
Whether the observable is Pauli-like, that is, has eigenvalues of \(\pm 1\).
Examples include the Pauli and Hadamard observables.
- Type:
bool
- property eigenvalues: ndarray
The eigenvalues of the observable ordered by computational basis state.
- Type:
np.ndarray
- fix_qubit(qubit: int) Observable [source]
Creates a copy of it acting on the given qubit.
Only defined for observables that act on 1 qubit.
- Parameters:
qubit (int) – The target qubit of the new observable.
- Returns:
Observable – A copy of this observable, acting on the new qubit.
- diagonalizing_gates(num_qubits: int | None = None) tuple[GateOperation, ...] [source]
The gates that diagonalize the observable in the computational basis.
- Parameters:
num_qubits (int, optional) – The number of qubits the observable acts on. Only used if no target is specified, in which case a gate is created for each target qubit. This only makes sense for single-qubit observables.
- Returns:
tuple[GateOperation, …] – The gates that diagonalize the observable in the computational basis, if it is not already in the computational basis. If there is no explicit target, this method returns a tuple of gates acting on every qubit.
- class braket.default_simulator.observables.PauliZ(targets: list[int] | None = None)[source]
Bases:
_InvolutoryMatrixObservable
Pauli-Z observable
Note
This observable refers to the same mathematical object as the gate operation of the same name, but is meant to be used differently; the observable is viewed as a Hermitian operator to be measured, while the gate is viewed as a unitary operator to evolve the state of the system.
- property targets: tuple[int, ...]
The indices of the qubits the operation applies to.
Note: For an index to be a target of an observable, the observable must have a nontrivial (i.e. non-identity) action on that index. For example, a tensor product observable with a Z factor on qubit j acts trivially on j, so j would not be a target. This does not apply to gate operations.
- Type:
tuple[int, …]
- property measured_qubits
The indices of the qubits that are measured for this observable.
Unlike
targets
, this includes indices on which the observable acts trivially. For example, a tensor product observable made entirely of n Z factors will have n measured qubits.- Type:
tuple[int, …]
- property is_standard: bool
Whether the observable is Pauli-like, that is, has eigenvalues of \(\pm 1\).
Examples include the Pauli and Hadamard observables.
- Type:
bool
- property eigenvalues: ndarray
The eigenvalues of the observable ordered by computational basis state.
- Type:
np.ndarray
- fix_qubit(qubit: int) Observable [source]
Creates a copy of it acting on the given qubit.
Only defined for observables that act on 1 qubit.
- Parameters:
qubit (int) – The target qubit of the new observable.
- Returns:
Observable – A copy of this observable, acting on the new qubit.
- diagonalizing_gates(num_qubits: int | None = None) tuple[GateOperation, ...] [source]
The gates that diagonalize the observable in the computational basis.
- Parameters:
num_qubits (int, optional) – The number of qubits the observable acts on. Only used if no target is specified, in which case a gate is created for each target qubit. This only makes sense for single-qubit observables.
- Returns:
tuple[GateOperation, …] – The gates that diagonalize the observable in the computational basis, if it is not already in the computational basis. If there is no explicit target, this method returns a tuple of gates acting on every qubit.
- class braket.default_simulator.observables.Hermitian(matrix: ndarray, targets: list[int] | None = None)[source]
Bases:
Observable
Arbitrary Hermitian observable
- property matrix: ndarray
The Hermitian matrix defining the observable.
- Type:
np.ndarray
- property targets: tuple[int, ...]
The indices of the qubits the operation applies to.
Note: For an index to be a target of an observable, the observable must have a nontrivial (i.e. non-identity) action on that index. For example, a tensor product observable with a Z factor on qubit j acts trivially on j, so j would not be a target. This does not apply to gate operations.
- Type:
tuple[int, …]
- property eigenvalues: ndarray
The eigenvalues of the observable ordered by computational basis state.
- Type:
np.ndarray
- apply(state: ndarray) ndarray [source]
Applies this observable to the given state.
- Parameters:
state (np.ndarray) – The state to apply the observable to.
- Returns:
np.ndarray – The state after the observable has been applied.
- fix_qubit(qubit: int) Observable [source]
Creates a copy of it acting on the given qubit.
Only defined for observables that act on 1 qubit.
- Parameters:
qubit (int) – The target qubit of the new observable.
- Returns:
Observable – A copy of this observable, acting on the new qubit.
- diagonalizing_gates(num_qubits: int | None = None) tuple[GateOperation, ...] [source]
The gates that diagonalize the observable in the computational basis.
- Parameters:
num_qubits (int, optional) – The number of qubits the observable acts on. Only used if no target is specified, in which case a gate is created for each target qubit. This only makes sense for single-qubit observables.
- Returns:
tuple[GateOperation, …] – The gates that diagonalize the observable in the computational basis, if it is not already in the computational basis. If there is no explicit target, this method returns a tuple of gates acting on every qubit.
- class braket.default_simulator.observables.TensorProduct(factors: list[Observable])[source]
Bases:
Observable
Tensor product of multiple observables.
- Parameters:
factors (list[Observable]) – The observables to combine together into a tensor product
- property factors: tuple[Observable]
- property targets: tuple[int, ...]
The indices of the qubits the operation applies to.
Note: For an index to be a target of an observable, the observable must have a nontrivial (i.e. non-identity) action on that index. For example, a tensor product observable with a Z factor on qubit j acts trivially on j, so j would not be a target. This does not apply to gate operations.
- Type:
tuple[int, …]
- property measured_qubits: tuple[int, ...]
The indices of the qubits that are measured for this observable.
Unlike
targets
, this includes indices on which the observable acts trivially. For example, a tensor product observable made entirely of n Z factors will have n measured qubits.- Type:
tuple[int, …]
- property eigenvalues: ndarray
The eigenvalues of the observable ordered by computational basis state.
- Type:
np.ndarray
- apply(state: ndarray) ndarray [source]
Applies this observable to the given state.
- Parameters:
state (np.ndarray) – The state to apply the observable to.
- Returns:
np.ndarray – The state after the observable has been applied.
- fix_qubit(qubit: int) Observable [source]
Creates a copy of it acting on the given qubit.
Only defined for observables that act on 1 qubit.
- Parameters:
qubit (int) – The target qubit of the new observable.
- Returns:
Observable – A copy of this observable, acting on the new qubit.
- diagonalizing_gates(num_qubits: int | None = None) tuple[GateOperation, ...] [source]
The gates that diagonalize the observable in the computational basis.
- Parameters:
num_qubits (int, optional) – The number of qubits the observable acts on. Only used if no target is specified, in which case a gate is created for each target qubit. This only makes sense for single-qubit observables.
- Returns:
tuple[GateOperation, …] – The gates that diagonalize the observable in the computational basis, if it is not already in the computational basis. If there is no explicit target, this method returns a tuple of gates acting on every qubit.