braket.circuits.quantum_operator module
- class braket.circuits.quantum_operator.QuantumOperator(qubit_count: int | None, ascii_symbols: Sequence[str])[source]
Bases:
Operator
A quantum operator is the definition of a quantum operation for a quantum device.
Initializes a
QuantumOperator
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this quantum operator acts on. If all instances of the operator act on the same number of qubits, this argument should be
None
, andfixed_qubit_count
should be implemented to return the qubit count; iffixed_qubit_count
is implemented and an int is passed in, it must equalfixed_qubit_count
, or instantiation will raise a ValueError. An int must be passed in if instances can have a varying number of qubits, in which casefixed_qubit_count
should not be implemented,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:
TypeError –
qubit_count
is not an intValueError –
qubit_count
is less than 1,ascii_symbols
areNone
,fixed_qubit_count
is implemented and and not equal toqubit_count
, orlen(ascii_symbols) != qubit_count
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- property qubit_count: int
The number of qubits this quantum operator acts on.
- Type:
int
- property ascii_symbols: tuple[str, ...]
Returns the ascii symbols for the quantum operator.
- Type:
tuple[str, …]
- property name: str
Returns the name of the quantum operator
- Returns:
str – The name of the quantum operator as a string
- to_ir(*args: Any, **kwargs: Any) Any [source]
Returns IR representation of quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
Any – The the canonical intermediate representation of the operator.
- to_matrix(*args: Any, **kwargs: Any) 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
- matrix_equivalence(other: QuantumOperator) bool [source]
Whether the matrix form of two quantum operators are equivalent
- Parameters:
other (QuantumOperator) – Quantum operator instance to compare this quantum operator to
- Returns:
bool – If matrix forms of this quantum operator and the other quantum operator are equivalent