def test_generate_circuit_with_ising_operator(self, ansatz, symbols_map,
                                                  target_unitary):
        # When
        ansatz.cost_hamiltonian = change_operator_type(ansatz.cost_hamiltonian,
                                                       IsingOperator)

        parametrized_circuit = ansatz._generate_circuit()
        evaluated_circuit = parametrized_circuit.bind(symbols_map)
        final_unitary = evaluated_circuit.to_unitary()

        # Then
        assert compare_unitary(final_unitary, target_unitary, tol=1e-10)
    def test_generate_circuit(self, ansatz):
        # Given
        symbols_map = create_symbols_map(number_of_params=4)
        target_unitary = create_XZ1_target_unitary(number_of_params=4)

        # When
        parametrized_circuit = ansatz._generate_circuit()
        evaluated_circuit = parametrized_circuit.bind(symbols_map)
        final_unitary = evaluated_circuit.to_unitary()

        # Then
        assert compare_unitary(final_unitary, target_unitary, tol=1e-10)
    def test_generate_circuit_type_2(self, ansatz):
        # Given
        symbols_map = create_symbols_map(number_of_params=4)
        target_unitary = create_XZ2_target_unitary(number_of_params=4)

        ansatz.use_k_body_z_operators = False

        # When
        parametrized_circuit = ansatz._generate_circuit()
        evaluated_circuit = parametrized_circuit.bind(symbols_map)
        final_unitary = evaluated_circuit.to_unitary()
        # Then
        assert compare_unitary(final_unitary, target_unitary, tol=1e-10)
    def test_generate_circuit_with_ising_operator(self, ansatz,
                                                  number_of_layers, thetas):
        # When
        ansatz.cost_hamiltonian = change_operator_type(ansatz.cost_hamiltonian,
                                                       IsingOperator)

        parametrized_circuit = ansatz._generate_circuit()
        symbols_map = create_symbols_map(number_of_layers)
        target_unitary = create_target_unitary(thetas, number_of_layers)
        evaluated_circuit = parametrized_circuit.evaluate(symbols_map)
        final_unitary = evaluated_circuit.to_unitary()

        # Then
        assert compare_unitary(final_unitary, target_unitary, tol=1e-10)
    def test_generate_circuit_with_k_body_depth_greater_than_1(self, ansatz):
        # Given
        symbols_map = create_symbols_map(number_of_params=6)
        target_unitary = create_XZ1_target_unitary(number_of_params=6, k_body_depth=2)

        ansatz.number_of_layers = 2

        # When
        parametrized_circuit = ansatz._generate_circuit()
        evaluated_circuit = parametrized_circuit.bind(symbols_map)
        final_unitary = evaluated_circuit.to_unitary()

        # Then
        assert compare_unitary(final_unitary, target_unitary, tol=1e-10)
    def test_time_evolution_with_symbolic_time_produces_correct_unitary(
            self, hamiltonian, time_value, order):
        time_symbol = sympy.Symbol("t")
        symbols_map = {time_symbol: time_value}

        expected_zquantum_circuit = _zquantum_exponentiate_hamiltonian(
            hamiltonian, time_value, order)

        reference_unitary = expected_zquantum_circuit.to_unitary()

        unitary = (time_evolution(
            hamiltonian, time_symbol,
            trotter_order=order).bind(symbols_map).to_unitary())

        assert compare_unitary(unitary, reference_unitary, tol=1e-10)
Exemplo n.º 7
0
    def test_time_evolution_with_symbolic_time_produces_correct_unitary(
            self, hamiltonian, time_value, order):
        time_symbol = sympy.Symbol("t")
        symbols_map = {time_symbol: time_value}

        cirq_qubits = cirq.LineQubit(0), cirq.LineQubit(1)

        expected_cirq_circuit = _cirq_exponentiate_hamiltonian(
            hamiltonian, cirq_qubits, time_value, order)

        reference_unitary = cirq.unitary(expected_cirq_circuit)

        unitary = (time_evolution(
            hamiltonian, time_symbol,
            trotter_order=order).bind(symbols_map).to_unitary())

        assert compare_unitary(unitary, reference_unitary, tol=1e-10)
Exemplo n.º 8
0
    def test_create_layer_of_gates_parametrized(self):
        # Given
        single_qubit_gate = "Ry"
        n_qubits_list = [2, 3, 4, 10]

        for n_qubits in n_qubits_list:
            # Given
            params = [x for x in range(0, n_qubits)]
            test = cirq.Circuit()
            qubits = [cirq.LineQubit(x) for x in range(0, n_qubits)]
            for i in range(0, n_qubits):
                test.append(cirq.ry(params[i]).on(qubits[i]))
            u_cirq = test._unitary_()

            # When
            circ = create_layer_of_gates(n_qubits, single_qubit_gate, params)
            unitary = circ.to_cirq()._unitary_()

            # Then
            self.assertEqual(circ.n_multiqubit_gates, 0)
            self.assertEqual(compare_unitary(unitary, u_cirq, tol=1e-10), True)
Exemplo n.º 9
0
 def test_compare_unitary(self):
     # Given
     U1 = unitary_group.rvs(4)
     U2 = unitary_group.rvs(4)
     # When/Then
     assert not compare_unitary(U1, U2)