예제 #1
0
    def begin_circuit(self,
                      num_subsystems,
                      cutoff_dim=None,
                      hbar=2,
                      pure=True,
                      **kwargs):
        r"""
        Create a quantum circuit (initialized in vacuum state) with the number of modes
        equal to num_subsystems and a Fock-space cutoff dimension of cutoff_dim.

        Args:
            num_subsystems (int): number of modes the circuit should begin with
            cutoff_dim (int): numerical cutoff dimension in Fock space for each mode.
                ``cutoff_dim=D`` represents the Fock states :math:`|0\rangle,\dots,|D-1\rangle`.
                This argument is **required** for the Fock backend.
            hbar (float): The value of :math:`\hbar` to initialise the circuit with, depending on the conventions followed.
                By default, :math:`\hbar=2`. See :ref:`conventions` for more details.
            pure (bool): whether to begin the circuit in a pure state representation
        """
        # pylint: disable=attribute-defined-outside-init
        if cutoff_dim is None:
            raise ValueError(
                "Argument 'cutoff_dim' must be passed to the Fock backend")
        elif not isinstance(cutoff_dim, int):
            raise ValueError(
                "Argument 'cutoff_dim' must be a positive integer")
        elif not isinstance(num_subsystems, int):
            raise ValueError(
                "Argument 'num_subsystems' must be a positive integer")
        elif not isinstance(pure, bool):
            raise ValueError("Argument 'pure' must be either True or False")

        self._init_modes = num_subsystems
        self.qreg = QReg(num_subsystems, cutoff_dim, hbar, pure)
        self._modeMap = ModeMap(num_subsystems)
    def begin_circuit(self, num_subsystems, **kwargs):
        r"""Instantiate a quantum circuit.

        Instantiates a representation of a quantum optical state with ``num_subsystems`` modes.
        The state is initialized to vacuum.

        The modes in the circuit are indexed sequentially using integers, starting from zero.
        Once an index is assigned to a mode, it can never be re-assigned to another mode.
        If the mode is deleted its index becomes invalid.
        An operation acting on an invalid or unassigned mode index raises an ``IndexError`` exception.

        Args:
            num_subsystems (int): number of modes in the circuit

        Keyword Args:
            cutoff_dim (int): Numerical Hilbert space cutoff dimension for the modes.
                For each mode, the simulator can represent the Fock states :math:`\ket{0}, \ket{1}, \ldots, \ket{\text{cutoff_dim}-1}`.
            pure (bool): If True (default), use a pure state representation (otherwise will use a mixed state representation).
        """
        cutoff_dim = kwargs.get('cutoff_dim', None)
        pure = kwargs.get('pure', True)
        if cutoff_dim is None:
            raise ValueError("Argument 'cutoff_dim' must be passed to the Fock backend")
        if not isinstance(cutoff_dim, int):
            raise ValueError("Argument 'cutoff_dim' must be a positive integer")
        if not isinstance(num_subsystems, int):
            raise ValueError("Argument 'num_subsystems' must be a positive integer")
        if not isinstance(pure, bool):
            raise ValueError("Argument 'pure' must be either True or False")

        self._init_modes = num_subsystems
        self.circuit = Circuit(num_subsystems, cutoff_dim, pure)
        self._modemap = ModeMap(num_subsystems)
예제 #3
0
    def begin_circuit(self,
                      num_subsystems,
                      *,
                      cutoff_dim=None,
                      pure=True,
                      **kwargs):
        r"""
        Create a quantum circuit (initialized in vacuum state) with the number of modes
        equal to num_subsystems and a Fock-space cutoff dimension of cutoff_dim.

        Args:
            num_subsystems (int): number of modes the circuit should begin with
            cutoff_dim (int): numerical cutoff dimension in Fock space for each mode.
                ``cutoff_dim=D`` represents the Fock states :math:`|0\rangle,\dots,|D-1\rangle`.
                This argument is **required** for the Fock backend.
            pure (bool): whether to begin the circuit in a pure state representation
        """
        # pylint: disable=attribute-defined-outside-init
        if cutoff_dim is None:
            raise ValueError(
                "Argument 'cutoff_dim' must be passed to the Fock backend")
        if not isinstance(cutoff_dim, int):
            raise ValueError(
                "Argument 'cutoff_dim' must be a positive integer")
        if not isinstance(num_subsystems, int):
            raise ValueError(
                "Argument 'num_subsystems' must be a positive integer")
        if not isinstance(pure, bool):
            raise ValueError("Argument 'pure' must be either True or False")

        self._init_modes = num_subsystems
        self.circuit = Circuit(num_subsystems, cutoff_dim, pure)
        self._modemap = ModeMap(num_subsystems)
예제 #4
0
    def begin_circuit(self,
                      num_subsystems,
                      cutoff_dim=None,
                      hbar=2,
                      pure=True,
                      **kwargs):
        r"""Create a quantum circuit (initialized in vacuum state) with the number of modes
        equal to num_subsystems and a Fock-space cutoff dimension of cutoff_dim.

        Args:
            num_subsystems (int): number of modes the circuit should begin with
            cutoff_dim (int): numerical cutoff dimension in Fock space for each mode.
                ``cutoff_dim=D`` represents the Fock states :math:`|0\rangle,\dots,|D-1\rangle`.
                This argument is **required** for the Tensorflow backend.
            hbar (float): The value of :math:`\hbar` to initialise the circuit with, depending on the conventions followed.
                By default, :math:`\hbar=2`. See :ref:`conventions` for more details.
            pure (bool): whether to begin the circuit in a pure state representation
            **kwargs: optional keyword arguments which will be passed to the underlying circuit class

                * **batch_size** (*None* or *int*): the size of the batch-axis dimension. If None, no batch-axis will be used.
        """
        # pylint: disable=too-many-arguments,attribute-defined-outside-init
        with tf.name_scope('Begin_circuit'):
            batch_size = kwargs.get('batch_size', None)

            if cutoff_dim is None:
                raise ValueError(
                    "Argument 'cutoff_dim' must be passed to the Tensorflow backend"
                )

            if not isinstance(num_subsystems, int):
                raise ValueError(
                    "Argument 'num_subsystems' must be a positive integer")
            elif not isinstance(cutoff_dim, int):
                raise ValueError(
                    "Argument 'cutoff_dim' must be a positive integer")
            elif not isinstance(pure, bool):
                raise ValueError(
                    "Argument 'pure' must be either True or False")
            elif batch_size == 1:
                raise ValueError(
                    "batch_size of 1 not supported, please use different batch_size or set batch_size=None"
                )
            else:
                self._modemap = ModeMap(num_subsystems)
                circuit = Circuit(self._graph, num_subsystems, cutoff_dim,
                                  hbar, pure, batch_size)

        self._init_modes = num_subsystems
        self.circuit = circuit
예제 #5
0
    def begin_circuit(self, num_subsystems, **kwargs):
        r"""Instantiate a quantum circuit.

        Instantiates a representation of a quantum optical state with ``num_subsystems`` modes.
        The state is initialized to vacuum.

        The modes in the circuit are indexed sequentially using integers, starting from zero.
        Once an index is assigned to a mode, it can never be re-assigned to another mode.
        If the mode is deleted its index becomes invalid.
        An operation acting on an invalid or unassigned mode index raises an ``IndexError`` exception.

        Args:
            num_subsystems (int): number of modes in the circuit

        Keyword Args:
            cutoff_dim (int): Numerical Hilbert space cutoff dimension for the modes.
                For each mode, the simulator can represent the Fock states :math:`\ket{0}, \ket{1}, \ldots, \ket{\text{cutoff_dim}-1}`.
            pure (bool): If True (default), use a pure state representation (otherwise will use a mixed state representation).
            batch_size (None or int): Size of the batch-axis dimension. If None, no batch-axis will be used.
            dtype (tf.DType): Complex Tensorflow Tensor type representation, either ``tf.complex64`` (default) or ``tf.complex128``.
                Note, ``tf.complex128`` will increase memory usage substantially.
        """
        cutoff_dim = kwargs.get("cutoff_dim", None)
        pure = kwargs.get("pure", True)
        batch_size = kwargs.get("batch_size", None)
        dtype = kwargs.get("dtype", tf.complex64)

        if cutoff_dim is None:
            raise ValueError("Argument 'cutoff_dim' must be passed to the TensorFlow backend")

        if not isinstance(num_subsystems, int):
            raise ValueError("Argument 'num_subsystems' must be a positive integer")
        if not isinstance(cutoff_dim, int):
            raise ValueError("Argument 'cutoff_dim' must be a positive integer")
        if not isinstance(pure, bool):
            raise ValueError("Argument 'pure' must be either True or False")
        if not dtype in (tf.complex64, tf.complex128):
            raise ValueError("Argument 'dtype' must be a complex Tensorflow DType")
        if batch_size == 1:
            raise ValueError(
                "batch_size of 1 not supported, please use different batch_size or set batch_size=None"
            )

        with tf.name_scope("Begin_circuit"):
            self._modemap = ModeMap(num_subsystems)
            circuit = Circuit(num_subsystems, cutoff_dim, pure, batch_size, dtype)

        self._init_modes = num_subsystems
        self.circuit = circuit