コード例 #1
0
 def target_unitary(self, beta, gamma, symbols_map):
     target_circuit = Circuit()
     target_circuit += H(0)
     target_circuit += H(1)
     target_circuit += RZ(2 * gamma)(0)
     target_circuit += RZ(2 * gamma)(1)
     target_circuit += RX(2 * beta)(0)
     target_circuit += RX(2 * beta)(1)
     return target_circuit.bind(symbols_map).to_unitary()
コード例 #2
0
def create_X_target_unitary(number_of_params, k_body_depth=1):
    thetas = create_thetas(number_of_params)
    symbols_map = create_symbols_map(number_of_params)

    target_circuit = Circuit()
    # Add an x operator to every qubit
    for i in range(3):
        target_circuit += create_x_operator(i, thetas[i])

    if k_body_depth == 2:
        target_circuit += create_2_qubit_x_operator(0, 1, thetas[3])
        target_circuit += create_2_qubit_x_operator(0, 2, thetas[4])
        target_circuit += create_2_qubit_x_operator(1, 2, thetas[5])

    return target_circuit.bind(symbols_map).to_unitary()
コード例 #3
0
    def test_commutes_with_parameter_substitution(self):
        theta, gamma = sympy.symbols("theta, gamma")
        circuit = Circuit([
            RX(theta / 2)(0),
            X(1),
            RY(gamma / 4).controlled(1)(1, 2),
            YY(0.1)(0, 4)
        ])

        symbols_map = {theta: 0.1, gamma: 0.5}
        parameterized_unitary = circuit.to_unitary()
        unitary = circuit.bind(symbols_map).to_unitary()

        np.testing.assert_array_almost_equal(
            np.array(parameterized_unitary.subs(symbols_map), dtype=complex),
            unitary)
コード例 #4
0
def create_XZ1_target_unitary(number_of_params, k_body_depth=1):
    thetas = create_thetas(number_of_params)
    symbols_map = create_symbols_map(number_of_params)

    target_circuit = Circuit()
    target_circuit += create_x_operator(0, thetas[0])
    target_circuit += RZ(2 * thetas[1])(0)

    target_circuit += create_x_operator(1, thetas[2])
    target_circuit += RZ(2 * thetas[3])(1)

    if k_body_depth == 2:
        target_circuit += create_2_qubit_x_operator(0, 1, thetas[4])
        target_circuit += CNOT(0, 1)
        target_circuit += RZ(2 * thetas[5])(1)
        target_circuit += CNOT(0, 1)

    return target_circuit.bind(symbols_map).to_unitary()
コード例 #5
0
def create_target_unitary(thetas, number_of_layers):
    target_circuit = Circuit()
    target_circuit += RY(thetas[0])(0)
    target_circuit += RY(thetas[1])(1)
    betas = create_betas(number_of_layers)
    gammas = create_gammas(number_of_layers)
    symbols_map = create_symbols_map(number_of_layers)
    for layer_id in range(number_of_layers):
        beta = betas[layer_id]
        gamma = gammas[layer_id]
        target_circuit += RZ(2.0 * gamma)(0)
        target_circuit += RZ(2.0 * gamma)(1)
        target_circuit += RY(-thetas[0])(0)
        target_circuit += RY(-thetas[1])(1)
        target_circuit += RZ(-2.0 * beta)(0)
        target_circuit += RZ(-2.0 * beta)(1)
        target_circuit += RY(thetas[0])(0)
        target_circuit += RY(thetas[1])(1)

    return target_circuit.bind(symbols_map).to_unitary()