def test_piecewise_polynomial_function(self, num_state_qubits, breakpoints, coeffs):
        """Test the piecewise linear rotations."""

        def pw_poly(x):
            for i, point in enumerate(reversed(breakpoints)):
                if x >= point:
                    # Rescale the coefficients to take into account the 2 * theta argument from the
                    # rotation gates
                    rescaled_c = [coeff / 2 for coeff in coeffs[-(i + 1)][::-1]]
                    return np.poly1d(rescaled_c)(x)
            return 0

        pw_polynomial_rotations = PiecewisePolynomialPauliRotations(num_state_qubits, breakpoints,
                                                                    coeffs)

        self.assertFunctionIsCorrect(pw_polynomial_rotations, pw_poly)
    def test_piecewise_polynomial_rotations_mutability(self):
        """Test the mutability of the linear rotations circuit."""
        def pw_poly(x):
            for i, point in enumerate(reversed(breakpoints[:len(coeffs)])):
                if x >= point:
                    # Rescale the coefficients to take into account the 2 * theta argument from the
                    # rotation gates
                    rescaled_c = [
                        coeff / 2 for coeff in coeffs[-(i + 1)][::-1]
                    ]
                    return np.poly1d(rescaled_c)(x)
            return 0

        pw_polynomial_rotations = PiecewisePolynomialPauliRotations()

        with self.subTest(msg="missing number of state qubits"):
            with self.assertRaises(AttributeError):  # no state qubits set
                print(pw_polynomial_rotations.draw())

        with self.subTest(
                msg="default setup, just setting number of state qubits"):
            pw_polynomial_rotations.num_state_qubits = 2
            self.assertFunctionIsCorrect(pw_polynomial_rotations,
                                         lambda x: 1 / 2)

        with self.subTest(msg="setting non-default values"):
            breakpoints = [0, 2]
            coeffs = [[0, -2 * 1.2], [-2 * 1, 2 * 1, 2 * 3]]
            pw_polynomial_rotations.breakpoints = breakpoints
            pw_polynomial_rotations.coeffs = coeffs
            self.assertFunctionIsCorrect(pw_polynomial_rotations, pw_poly)

        with self.subTest(msg="changing all values"):
            pw_polynomial_rotations.num_state_qubits = 4
            breakpoints = [1, 3, 6]
            coeffs = [[0, -2 * 1.2], [-2 * 1, 2 * 1, 2 * 3], [-2 * 2]]
            pw_polynomial_rotations.breakpoints = breakpoints
            pw_polynomial_rotations.coeffs = coeffs
            self.assertFunctionIsCorrect(pw_polynomial_rotations, pw_poly)