def test_no_1_qiskrypt_quantum_pauli_x_transform_1_qubit(self):
        """
        Test Case #1:

        - Setup the Qiskrypt's Quantum Pauli-X Transform, given a Qiskrypt's Quantum Circuit,
          and apply the Transform to the respective indexes of IBM Qiskit's Quantum Registers and qubits,
          for 1 qubit involved.

        Description of the Steps for the Unitary Test:
        1) The required arguments for the Qiskrypt's Quantum Pauli-X Transform are passed to it,
           i.e., a custom name for it, the associated Qiskrypt's Quantum Circuit,
           and two lists of indexes of IBM Qiskit's Quantum Registers and qubits;
        2) The Pauli-X Transform it is applied to the respective indexes of
           IBM Qiskit's Quantum Registers and qubits defined previously
           (i.e., 1 IBM Qiskit's Quantum Register and 1 qubit);

        Return OK (or FAIL) if, all the Tests performed are OK (or FAIL, otherwise).
        """

        quantum_register_num_qubits = 1
        """
        Set the number of qubits for the Qiskrypt's Quantum Register.
        """

        qiskrypt_quantum_register_quantum_pauli_x_transform_1_qubit = \
            QiskryptQuantumRegister("qu_reg_pauli_x_transform_1", quantum_register_num_qubits)
        """
        Create a Qiskrypt's Quantum Register with 1 qubit.
        """

        qiskrypt_quantum_circuit_quantum_pauli_x_transform_1_qubit = \
            QiskryptQuantumCircuit("qu_circ_pauli_x_transform_1",
                                   qiskrypt_quantum_registers=[qiskrypt_quantum_register_quantum_pauli_x_transform_1_qubit],
                                   qiskrypt_fully_quantum_registers=None,
                                   qiskrypt_semi_quantum_registers=None,
                                   qiskrypt_ancilla_quantum_registers=None,
                                   qiskrypt_ancilla_fully_quantum_registers=None,
                                   qiskrypt_ancilla_semi_quantum_registers=None,
                                   qiskrypt_classical_registers=None,
                                   global_phase=0, qiskit_quantum_circuit=None)
        """
        Create a Qiskrypt's Quantum Circuit with
        the previously created Qiskrypt's Quantum Register.
        """

        qiskrypt_quantum_pauli_x_transform = \
            QiskryptQuantumPauliXTransform("pauli_x_transform_1",
                                           qiskrypt_quantum_circuit_quantum_pauli_x_transform_1_qubit,
                                           ([0] * quantum_register_num_qubits),
                                           [*range(quantum_register_num_qubits)])
        """
        Create the Qiskrypt's Quantum Pauli-X Transform, for 1 Qiskrypt's Quantum Register and 1 qubit.
        """

        qiskrypt_quantum_pauli_x_transform.apply_transform()
        """
        Apply the Quantum Pauli-X Transform to the Qiskrypt's Quantum Registers and qubits involved.
        """

        qiskit_state_vector_backend = Aer.get_backend("statevector_simulator")
        """
        Getting the Aer Simulator Backend for the State Vector Representation
        (i.e., the quantum_regime state represented as its state vector).
        """

        final_quantum_state_vector_state = \
            execute(qiskrypt_quantum_circuit_quantum_pauli_x_transform_1_qubit.qiskit_quantum_circuit,
                    qiskit_state_vector_backend).result().get_statevector()
        """
        Execute the IBM Qiskit's Quantum Circuit of the Qiskrypt's Quantum Circuit
        and store the resulted quantum_regime state represented in a final state vector.
        """

        num_possible_outcomes = (2**quantum_register_num_qubits)
        """
        Compute the number of possible outcomes (i.e., 2^(quantum_register_num_qubits)).
        """

        quantum_pauli_x_transform_1_qubit_array_expected_amplitudes = \
            full((num_possible_outcomes,), (0. + 0.j))
        """
        Create and fill an array with the zeros for the expected values of
        the Qiskrypt's Quantum Pauli-X Transform.
        """

        quantum_pauli_x_transform_1_qubit_array_expected_amplitudes[(
            num_possible_outcomes - 1)] = (1. + 0.j)
        """
        Fill the last position of the expected values of
        the Qiskrypt's Quantum Pauli-X Transform, with 1.
        """

        assert_allclose(
            final_quantum_state_vector_state,
            quantum_pauli_x_transform_1_qubit_array_expected_amplitudes,
            rtol=1e-7,
            atol=1e-7)
        """
        Perform the Assertion of all close values in the values of the quantum_regime state,
        represented by its state vector describing the given qubit,
        after be applied the Qiskrypt's Quantum Pauli-X Transform.
        """
        """
        Dummy Assert Equal for the Unittest.
        """
        self.assertEqual(True, True)
    def test_no_1_qiskrypt_quantum_register_1_qubit(self):
        """
        Test Case #1:

        - Create a Qiskrypt's Quantum Register, with 1 qubit.

        Return OK (or FAIL) if, all the Tests performed are OK (or FAIL, otherwise).
        """

        quantum_register_name = "qu_reg"
        """
        Set the name of the Qiskrypt's Quantum Register.
        """

        quantum_register_num_qubits = 1
        """
        Set the number of qubits for the Qiskrypt's Quantum Register.
        """

        qiskrypt_quantum_register = \
            QiskryptQuantumRegister(name=quantum_register_name,
                                    num_qubits=quantum_register_num_qubits,
                                    qiskit_quantum_register=None)
        """
        Create a Qiskrypt's Quantum Register, given its name and number of qubits.
        """

        assert (quantum_register_name == qiskrypt_quantum_register.get_name())
        """
        Assertion for the name of the Qiskrypt's Quantum Register.
        """

        assert (quantum_register_num_qubits ==
                qiskrypt_quantum_register.get_num_qubits())
        """
        Assertion for the number of qubits of the Qiskrypt's Quantum Register.
        """

        assert (isinstance(
            qiskrypt_quantum_register.get_qiskit_quantum_register(),
            QuantumRegister))
        """
        Assertion for the IBM's Qiskit Quantum Register of the Qiskrypt's Quantum Register.
        """

        assert (isinstance(qiskrypt_quantum_register, QiskryptQuantumRegister))
        """
        Assertion for the own Qiskrypt's Quantum Register, regarding a Qiskrypt's Quantum Register.
        """

        assert (not isinstance(qiskrypt_quantum_register,
                               QiskryptFullyQuantumRegister))
        """
        Assertion for the own Qiskrypt's Quantum Register, regarding a Qiskrypt's Fully-Quantum Register.
        """

        assert (not isinstance(qiskrypt_quantum_register,
                               QiskryptSemiQuantumRegister))
        """
        Assertion for the own Qiskrypt's Quantum Register, regarding a Qiskrypt's Semi-Quantum Register.
        """

        assert (not isinstance(qiskrypt_quantum_register,
                               QiskryptClassicalRegister))
        """
        Assertion for the own Qiskrypt's Quantum Register, regarding a Qiskrypt's Classical Register.
        """
        """
        Dummy Assert Equal for the Unittest
        """
        self.assertEqual(True, True)
Пример #3
0
    def configure(self, dice_type: str) -> None:
        """
        Configure the Qiskrypt's Quantum Dice Throwing,
        given the type of Dice for its configuration.

        :param dice_type: the type of the Dice for
                          the Qiskrypt's Quantum Dice Throwing.
        """

        if not self.is_configured():
            """
            If the Qiskrypt's Quantum Dice Throwing is not configured yet.
            """

            if dice_type in DICE_TYPES:
                """
                If the given type of the Dice for
                the Qiskrypt's Quantum Dice Throwing is valid.
                """

                self.dice_type = dice_type
                """
                Set the Dice type of the configuration to be used on
                the Qiskrypt's Quantum Dice Throwing,
                according to the given Dice type.
                """

                self.num_dice_sides = NUM_SIDES_FOR_DICE_TYPES[dice_type]
                """
                Set the number of sides of the Dice configured for
                the Qiskrypt's Quantum Dice Throwing, from the size given.
                """

                num_qubits = num_bits = ceil(log2(self.num_dice_sides))
                """
                Set the number of qubits and bits, according to
                the respective number of sides of the Dice configured.
                """

                qiskrypt_quantum_register_quantum_dice_throwing = \
                    QiskryptQuantumRegister("qu_reg_dice_throw", num_qubits)
                """
                Create a Qiskrypt's Quantum Register for the current Qiskrypt's Quantum Dice Throwing,
                with a number of qubits corresponding to the respective number of sides of the Dice configured.
                """

                qiskrypt_classical_register_quantum_dice_throwing = \
                    QiskryptClassicalRegister("cl_reg_dice_throw", num_bits)
                """
                Create a Qiskrypt's Classical Register for the current Qiskrypt's Quantum Dice Throwing,
                with a number of bits corresponding to the respective number of sides of the Dice configured.
                """

                qiskrypt_quantum_circuit = \
                    QiskryptQuantumCircuit("qu_circ_dice_throw",
                                           qiskrypt_quantum_registers=[qiskrypt_quantum_register_quantum_dice_throwing],
                                           qiskrypt_fully_quantum_registers=None,
                                           qiskrypt_semi_quantum_registers=None,
                                           qiskrypt_ancilla_quantum_registers=None,
                                           qiskrypt_ancilla_fully_quantum_registers=None,
                                           qiskrypt_ancilla_semi_quantum_registers=None,
                                           qiskrypt_classical_registers=[qiskrypt_classical_register_quantum_dice_throwing],
                                           global_phase=0, qiskit_quantum_circuit=None)
                """
                Create a Qiskrypt's Quantum Circuit with the both previously created
                Qiskrypt's Quantum Register and Qiskrypt's Classical Register.
                """

                self.qiskrypt_quantum_hadamard_transform = \
                    QiskryptQuantumHadamardTransform("quantum_hadamard_transform_qrg",
                                                     qiskrypt_quantum_circuit,
                                                     ([0] * num_qubits),
                                                     [*range(num_qubits)])
                """
                Setup the currently created Qiskrypt's Quantum Hadamard Transform for
                the Qiskrypt's Quantum Dice Throwing.
                """

                self.qiskrypt_quantum_hadamard_transform.apply_transform()
                """
                Apply the Quantum Hadamard Transform to the Qiskrypt's Quantum Registers and qubits involved
                in the current Qiskrypt's Quantum Hadamard Transform for the Qiskrypt's Quantum Dice Throwing.
                """

                self.qiskrypt_quantum_hadamard_transform \
                    .qiskrypt_quantum_circuit.measure_all_qubits_in_qiskit_quantum_register(0, 0)
                """
                Measure all the qubits in the IBM Qiskit's Quantum Register to
                the IBM Qiskit's Classical Register, in the Qiskrypt's Quantum Circuit of
                the current Qiskrypt's Quantum Hadamard Transform for the Qiskrypt's Quantum Dice Throwing.
                """

            else:
                """
                If the given type of the Dice for
                the Qiskrypt's Quantum Dice Throwing is not valid.
                """
                """
                Return/Raise a Dice Type Not Valid Error for
                the Qiskrypt's Quantum Dice Throwing.
                """
                self.raise_dice_type_not_valid_error()

            self.configured = True
            """
            Set the boolean flag to keep the information about if
            the Qiskrypt's Quantum Dice Throwing is configured or not, as True.
            """

        else:
            """
            If the Qiskrypt's Quantum Dice Throwing is already configured.
            """
            """
            Return/Raise a Dice Already Configured Error for
            the Qiskrypt's Quantum Dice Throwing.
            """
            self.raise_dice_already_configured_error()
Пример #4
0
    def initialise_qiskrypt_quantum_circuit(self) -> None:
        """
        Initialise the Qiskrypt's Quantum Circuit for the Qiskrypt's Quantum Coin Tossing.
        """

        if not self.is_qiskrypt_quantum_circuit_initialised(
        ) and not self.is_already_tossed():
            """
            If neither the Qiskrypt's Quantum Circuit for
            the Qiskrypt's Quantum Coin Tossing was initialised yet,
            nor the Coin was tossed yet.
            """

            quantum_register_name = "qu_reg_coin_toss"
            """
            Set the name of the Qiskrypt's Quantum Register.
            """

            qiskrypt_quantum_register_coin_tossing = \
                QiskryptQuantumRegister(name=quantum_register_name,
                                        num_qubits=NUM_QUBITS_FOR_COIN)
            """
            Create a Qiskrypt's Quantum Register, given its name and number of qubits.
            """

            classical_register_name = "cl_reg_coin_toss"
            """
            Set the name of the Qiskrypt's Classical Register.
            """

            qiskrypt_classical_register_coin_tossing = \
                QiskryptClassicalRegister(name=classical_register_name,
                                          num_bits=NUM_BITS_FOR_COIN)
            """
            Create a Qiskrypt's Classical Register, given its name and number of bits.
            """

            self.qiskrypt_quantum_circuit = \
                QiskryptQuantumCircuit("qu_circ_coin_toss",
                                       qiskrypt_quantum_registers=[qiskrypt_quantum_register_coin_tossing],
                                       qiskrypt_fully_quantum_registers=None,
                                       qiskrypt_semi_quantum_registers=None,
                                       qiskrypt_ancilla_quantum_registers=None,
                                       qiskrypt_ancilla_fully_quantum_registers=None,
                                       qiskrypt_ancilla_semi_quantum_registers=None,
                                       qiskrypt_classical_registers=[qiskrypt_classical_register_coin_tossing],
                                       global_phase=0, qiskit_quantum_circuit=None)
            """
            Set the Qiskrypt's Quantum Circuit for the Qiskrypt's Quantum Coin Tossing with
            the previously created Qiskrypt's Quantum and Classical Registers.
            """

            self.qiskrypt_quantum_circuit_initialised = True
            """
            Set the boolean flag to keep information about if
            the Qiskrypt's Quantum Circuit for the Qiskrypt's Quantum Coin Tossing
            was already initialised or not, as True.
            """

        else:
            """
            If the Qiskrypt's Quantum Circuit for
            the Qiskrypt's Quantum Coin Tossing was already initialised and/or
            the Coin was also already tossed.
            """

            if self.is_qiskrypt_quantum_circuit_initialised():
                """
                If the Qiskrypt's Quantum Circuit for
                the Qiskrypt's Quantum Coin Tossing was already initialised.
                """
                """
                Return/Raise a Quantum Circuit Already Initialised Error for
                the Qiskrypt's Quantum Coin Tossing.
                """
                self.raise_quantum_circuit_already_initialised_error()

            if self.is_already_tossed():
                """
                If the Coin was already tossed.
                """
                """
                Return/Raise a Coin Already Tossed Error for the Qiskrypt's Quantum Coin Tossing.
                """
                self.raise_coin_already_tossed_error()