Skip to content

Commit

Permalink
added typing
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesB-1qbit committed Nov 15, 2023
1 parent 7879bf9 commit 4e792c5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tangelo/toolboxes/operators/trim_trivial_qubits.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, Tuple, Union

import numpy as np

from tangelo.toolboxes.operators import QubitOperator, count_qubits
from tangelo.linq import Circuit
from tangelo.linq import Circuit, Gate
from tangelo.linq.helpers.circuits import pauli_string_to_of, pauli_of_to_string


def trim_trivial_operator(qu_op, trim_states, n_qubits=None, reindex=True):
def trim_trivial_operator(qu_op: QubitOperator, trim_states: Dict[int, int],
n_qubits: Union[None, int] = None, reindex: bool = True) -> QubitOperator:
"""
Calculate expectation values of a QubitOperator acting on qubits in a
trivial |0> or |1> state. Return a trimmed QubitOperator with updated coefficients
Expand Down Expand Up @@ -58,7 +61,7 @@ def trim_trivial_operator(qu_op, trim_states, n_qubits=None, reindex=True):
return qu_op_trim


def is_bitflip_gate(gate, atol=1e-5):
def is_bitflip_gate(gate: Gate, atol: float = 1e-5) -> bool:
"""
Check if a gate is a bitflip gate.
Expand Down Expand Up @@ -90,7 +93,7 @@ def is_bitflip_gate(gate, atol=1e-5):
return False


def trim_trivial_circuit(circuit: Circuit):
def trim_trivial_circuit(circuit: Circuit) -> Tuple[Circuit, Dict[int, int]]:
"""
Split Circuit into entangled and unentangled components.
Returns entangled Circuit, and the indices and states of unentangled qubits
Expand Down Expand Up @@ -161,7 +164,7 @@ def trim_trivial_circuit(circuit: Circuit):
return circuit_new, dict(sorted(trim_states.items()))


def trim_trivial_qubits(operator, circuit):
def trim_trivial_qubits(operator: QubitOperator, circuit: Circuit) -> Tuple[QubitOperator, Circuit]:
"""
Trim circuit and operator based on expectation values calculated from
trivial components of the circuit.
Expand Down

0 comments on commit 4e792c5

Please sign in to comment.