def test_binding_some_params_leaves_free_params(self): theta1, theta2, theta3 = sympy.symbols("theta1:4") circuit = Circuit([ RX(theta1)(0), RY(theta2)(1), RZ(theta3)(0), RX(theta2)(0), ]) bound_circuit = circuit.bind({theta1: 0.5, theta3: 3.14}) assert bound_circuit.free_symbols == {theta2}
def test_binding_all_params_leaves_no_free_symbols(self): alpha, beta, gamma = sympy.symbols("alpha,beta,gamma") circuit = Circuit([ RX(alpha)(0), RY(beta)(1), RZ(gamma)(0), RX(gamma)(0), ]) bound_circuit = circuit.bind({alpha: 0.5, beta: 3.14, gamma: 0}) assert not bound_circuit.free_symbols
def test_binding_excessive_params_binds_only_the_existing_ones(self): theta1, theta2, theta3 = sympy.symbols("theta1:4") other_param = sympy.symbols("other_param") circuit = Circuit([ RX(theta1)(0), RY(theta2)(1), RZ(theta3)(0), RX(theta2)(0), ]) bound_circuit = circuit.bind({theta1: -np.pi, other_param: 42}) assert bound_circuit.free_symbols == {theta2, theta3}
def test_circuit_bound_with_all_params_contains_bound_gates(self): theta1, theta2, theta3 = sympy.symbols("theta1:4") symbols_map = {theta1: 0.5, theta2: 3.14, theta3: 0} circuit = Circuit([ RX(theta1)(0), RY(theta2)(1), RZ(theta3)(0), RX(theta3)(0), ]) bound_circuit = circuit.bind(symbols_map) expected_circuit = Circuit([ RX(theta1).bind(symbols_map)(0), RY(theta2).bind(symbols_map)(1), RZ(theta3).bind(symbols_map)(0), RX(theta3).bind(symbols_map)(0), ]) assert bound_circuit == expected_circuit