Example #1
0
    def test_create_random_circuit(self, number_of_qubits, number_of_gates,
                                   seed):
        # Given
        expected_filename = "circuit.json"
        expected_circuit = _create_random_circuit(
            number_of_qubits,
            number_of_gates,
            seed=seed,
        )

        # When
        create_random_circuit(
            number_of_qubits=number_of_qubits,
            number_of_gates=number_of_gates,
            seed=seed,
        )

        # Then
        try:
            circuit = load_circuit(expected_filename)
            if seed is not None:
                assert circuit.gates == expected_circuit.gates
            else:
                assert circuit.gates != expected_circuit.gates
        finally:
            remove_file_if_exists(expected_filename)
Example #2
0
def create_random_circuit(number_of_qubits: int,
                          number_of_gates: int,
                          seed: Optional[int] = None):
    circuit = _create_random_circuit(number_of_qubits,
                                     number_of_gates,
                                     seed=seed)
    save_circuit(circuit, "circuit.json")
Example #3
0
 def input_circuits(self, request):
     number_of_qubits = 4
     number_of_gates = 10
     return [
         _create_random_circuit(number_of_qubits, number_of_gates, seed=RNDSEED + i)
         for i in range(request.param)
     ]
Example #4
0
    def test_add_ancilla_register_to_circuit_python_object(
        self, number_of_ancilla_qubits
    ):
        # Given
        number_of_qubits = 4
        number_of_gates = 10
        circuit = _create_random_circuit(
            number_of_qubits, number_of_gates, seed=RNDSEED
        )
        expected_extended_cirucit = _add_ancilla_register_to_circuit(
            copy.deepcopy(circuit), number_of_ancilla_qubits
        )
        expected_extended_circuit_filename = "extended-circuit.json"

        # When
        add_ancilla_register_to_circuit(number_of_ancilla_qubits, circuit)

        # Then
        try:
            extended_circuit = load_circuit(expected_extended_circuit_filename)
            assert (
                len(extended_circuit.qubits)
                == number_of_qubits + number_of_ancilla_qubits
            )
            assert extended_circuit.gates == expected_extended_cirucit.gates
        finally:
            remove_file_if_exists(expected_extended_circuit_filename)
Example #5
0
def create_random_circuit(number_of_qubits: int,
                          number_of_gates: int,
                          seed: Union[str, int] = "None"):
    circuit = _create_random_circuit(number_of_qubits,
                                     number_of_gates,
                                     seed=seed)
    save_circuit(circuit, "circuit.json")
Example #6
0
 def circuit_set(self, number_of_circuits):
     number_of_qubits = 4
     number_of_gates = 10
     circuit_set = [
         _create_random_circuit(number_of_qubits, number_of_gates, seed=RNDSEED)
         for _ in range(number_of_circuits)
     ]
     return circuit_set
Example #7
0
    def circuit_filename_and_number_of_ancilla_qubits(self, number_of_ancilla_qubits):
        number_of_qubits = 4
        number_of_gates = 10
        circuit = _create_random_circuit(
            number_of_qubits, number_of_gates, seed=RNDSEED
        )
        circuit_filename = "circuit.json"
        save_circuit(circuit, circuit_filename)

        yield circuit_filename, number_of_ancilla_qubits

        remove_file_if_exists(circuit_filename)