Ejemplo n.º 1
0
    def gate_property(self,
                      gate: str,
                      qubits: Union[int, Iterable[int]] = None,
                      name: str = None) -> Tuple[Any, datetime.datetime]:
        """
        Return the property of the given gate.

        Args:
            gate: Name of the gate.
            qubits: The qubit to find the property for.
            name: Optionally used to specify which gate property to return.

        Returns:
            Gate property as a tuple of the value and the time it was measured.

        Raises:
            BackendPropertyError: If the property is not found or name is
                                  specified but qubit is not.
        """
        try:
            result = self._gates[gate]
            if qubits is not None:
                if isinstance(qubits, int):
                    qubits = tuple([qubits])
                result = result[tuple(qubits)]
                if name:
                    result = result[name]
            elif name:
                raise BackendPropertyError(
                    "Provide qubits to get {n} of {g}".format(n=name, g=gate))
        except KeyError:
            raise BackendPropertyError(
                "Could not find the desired property for {g}".format(g=gate))
        return result
Ejemplo n.º 2
0
    def qubit_property(self,
                       qubit: int,
                       name: str = None) -> Tuple[Any, datetime.datetime]:
        """
        Return the property of the given qubit.

        Args:
            qubit: The property to look for.
            name: Optionally used to specify within the hierarchy which property to return.

        Returns:
            Qubit property as a tuple of the value and the time it was measured.

        Raises:
            BackendPropertyError: If the property is not found.
        """
        try:
            result = self._qubits[qubit]
            if name is not None:
                result = result[name]
        except KeyError:
            raise BackendPropertyError(
                "Couldn't find the propert{name} for qubit "
                "{qubit}.".format(name="y '" + name + "'" if name else "ies",
                                  qubit=qubit))
        return result
Ejemplo n.º 3
0
    def _apply_prefix(self, value: float, unit: str) -> float:
        """
        Given a SI unit prefix and value, apply the prefix to convert to
        standard SI unit.

        Args:
            value: The number to apply prefix to.
            unit: String prefix.

        Returns:
            Converted value.

        Raises:
            BackendPropertyError: If the units aren't recognized.
        """
        downfactors = {'p': 1e12, 'n': 1e9, 'u': 1e6, 'µ': 1e6, 'm': 1e3}
        upfactors = {'k': 1e3, 'M': 1e6, 'G': 1e9}
        if not unit:
            return value
        if unit[0] in downfactors:
            return value / downfactors[unit[0]]
        elif unit[0] in upfactors:
            return value * upfactors[unit[0]]
        else:
            raise BackendPropertyError(
                "Could not understand units: {u}".format(u=unit))
Ejemplo n.º 4
0
    def _apply_prefix(self, value: float, unit: str) -> float:
        """
        Given a SI unit prefix and value, apply the prefix to convert to
        standard SI unit.

        Args:
            value: The number to apply prefix to.
            unit: String prefix.

        Returns:
            Converted value.

        Raises:
            BackendPropertyError: If the units aren't recognized.
        """
        prefixes = {
            'p': 1e-12,
            'n': 1e-9,
            'u': 1e-6,
            'µ': 1e-6,
            'm': 1e-3,
            'k': 1e3,
            'M': 1e6,
            'G': 1e9
        }
        if not unit:
            return value
        try:
            return value * prefixes[unit[0]]
        except KeyError:
            raise BackendPropertyError(
                "Could not understand units: {u}".format(u=unit))
Ejemplo n.º 5
0
    def _apply_prefix(self, value: float, unit: str) -> float:
        """
        Given a SI unit prefix and value, apply the prefix to convert to
        standard SI unit.

        Args:
            value: The number to apply prefix to.
            unit: String prefix.

        Returns:
            Converted value.

        Raises:
            BackendPropertyError: If the units aren't recognized.
        """
        try:
            return apply_prefix(value, unit)
        except Exception as ex:
            raise BackendPropertyError(f"Could not understand units: {unit}") from ex