def test_setpoints_non_parameter_raises(): """ Test that putting some random function as a setpoint parameter will raise as expected. """ n_points_1 = Parameter('n_points_1', set_cmd=None, vals=vals.Ints()) n_points_2 = Parameter('n_points_2', set_cmd=None, vals=vals.Ints()) n_points_1.set(10) n_points_2.set(20) err_msg = (r"Setpoints is of type <class 'function'> " r"expcected a QCoDeS parameter") with pytest.raises(TypeError, match=err_msg): param_with_setpoints_1 = ParameterWithSetpoints( 'param_1', get_cmd=lambda: rand(n_points_1()), setpoints=(lambda x: x, ), vals=vals.Arrays(shape=(n_points_1, ))) param_with_setpoints_1 = ParameterWithSetpoints( 'param_1', get_cmd=lambda: rand(n_points_1()), vals=vals.Arrays(shape=(n_points_1, ))) with pytest.raises(TypeError, match=err_msg): param_with_setpoints_1.setpoints = (lambda x: x, )
def test_expand_setpoints_2d(parameters): n_points_1, n_points_2, n_points_3, \ setpoints_1, setpoints_2, setpoints_3 = parameters param_with_setpoints_2 = ParameterWithSetpoints( 'param_2', get_cmd=lambda: rand(n_points_1(), n_points_2()), vals=vals.Arrays(shape=(n_points_1, n_points_2))) param_with_setpoints_2.setpoints = (setpoints_1, setpoints_2) data = expand_setpoints_helper(param_with_setpoints_2) assert len(data) == 3 assert data[0][1].shape == data[1][1].shape assert data[0][1].shape == data[2][1].shape sp1 = data[0][1] sp2 = data[1][1] # the first set of setpoints should be repeated along the second axis for i in range(sp1.shape[1]): np.testing.assert_array_equal(sp1[:, i], np.arange(sp1.shape[0])) # the second set of setpoints should be repeated along the first axis for i in range(sp2.shape[0]): np.testing.assert_array_equal(sp2[i, :], np.arange(sp1.shape[1]))
def test_expand_setpoints_3d(parameters): n_points_1, n_points_2, n_points_3, \ setpoints_1, setpoints_2, setpoints_3 = parameters param_with_setpoints_3 = ParameterWithSetpoints( 'param_2', get_cmd=lambda: rand(n_points_1(), n_points_2(), n_points_3()), vals=vals.Arrays(shape=(n_points_1, n_points_2, n_points_3))) param_with_setpoints_3.setpoints = (setpoints_1, setpoints_2, setpoints_3) data = expand_setpoints_helper(param_with_setpoints_3) assert len(data) == 4 assert data[0][1].shape == data[1][1].shape assert data[0][1].shape == data[2][1].shape assert data[0][1].shape == data[3][1].shape sp1 = data[0][1] for i in range(sp1.shape[1]): for j in range(sp1.shape[2]): np.testing.assert_array_equal(sp1[:, i, j], np.arange(sp1.shape[0])) sp2 = data[1][1] for i in range(sp2.shape[0]): for j in range(sp2.shape[2]): np.testing.assert_array_equal(sp2[i, :, j], np.arange(sp2.shape[1])) sp3 = data[2][1] for i in range(sp3.shape[0]): for j in range(sp3.shape[1]): np.testing.assert_array_equal(sp3[i, j, :], np.arange(sp3.shape[2]))
def test_validation_shapes(): """ Test that various parameters with setpoints and shape combinations validate correctly. """ n_points_1 = Parameter('n_points_1', set_cmd=None, vals=vals.Ints()) n_points_2 = Parameter('n_points_2', set_cmd=None, vals=vals.Ints()) n_points_1.set(10) n_points_2.set(20) setpoints_1 = Parameter('setpoints_1', get_cmd=lambda: rand(n_points_1()), vals=vals.Arrays(shape=(n_points_1, ))) setpoints_2 = Parameter('setpoints_2', get_cmd=lambda: rand(n_points_2()), vals=vals.Arrays(shape=(n_points_2, ))) param_with_setpoints_1 = ParameterWithSetpoints( "param_1", get_cmd=lambda: rand(n_points_1()), setpoints=(setpoints_1, ), vals=vals.Arrays(shape=(n_points_1, )), ) assert ("<Arrays, shape: (<qcodes.parameters.parameter." "Parameter: n_points_1 at" in param_with_setpoints_1.__doc__) # the two shapes are the same so validation works param_with_setpoints_1.validate_consistent_shape() param_with_setpoints_1.validate(param_with_setpoints_1.get()) param_with_setpoints_2 = ParameterWithSetpoints( 'param_2', get_cmd=lambda: rand(n_points_1(), n_points_2()), vals=vals.Arrays(shape=(n_points_1, n_points_2))) param_with_setpoints_2.setpoints = (setpoints_1, setpoints_2) # 2d param_with_setpoints_2.validate_consistent_shape() param_with_setpoints_2.validate(param_with_setpoints_2.get())