braket.circuits.quantum_operator module¶

class
braket.circuits.quantum_operator.
QuantumOperator
(qubit_count: Optional[int], ascii_symbols: Sequence[str])[source]¶ Bases:
braket.circuits.operator.Operator
A quantum operator is the definition of a quantum operation for a quantum device.
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.

qubit_count
¶ The number of qubits this quantum operator acts on.
Type: int

ascii_symbols
¶ Returns the ascii symbols for the quantum operator.
Type: Tuple[str, ..]

name
¶ Returns the name of the quantum operator
Returns: str – The name of the quantum operator as a string

to_ir
(*args, **kwargs) → Any[source]¶ Returns IR representation of quantum operator.
Returns: Any – The the canonical intermediate representation of the operator.

to_matrix
(*args, **kwargs) → numpy.ndarray[source]¶ Returns a matrix representation of the quantum operator
Returns: ndarray – A matrix representation of the quantum operator

matrix_equivalence
(other: braket.circuits.quantum_operator.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
 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