Exemplo n.º 1
0
              "whether this change is wanted or not. \n\nBroken ops: "
              "[\n\t{}\n]".format("\n\t".join(broken_ops)))
    return is_bc


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Process some integers.")
    parser.add_argument(
        "--existing-schemas",
        help="filename to load existing schemas",
        type=str,
        default="schemas.txt",
    )
    args = parser.parse_args()
    existing_schema_dict = dict()
    slist = []
    with open(args.existing_schemas, "r") as f:
        while True:
            line = f.readline()
            if not line:
                break

            if dont_parse(line.strip()):
                print("Not parsing schema line: ", line.strip())
                continue
            s = parse_schema(line.strip())
            slist.append(s)

    if not check_bc(slist):
        sys.exit(1)
Exemplo n.º 2
0
 def test_backward_compatible_arguments(self):
     old_schema = parse_schema(
         'any(Tensor self, *, Tensor b, int c) -> Tensor')
     # No-BC: A new schema with less arguments.
     new_schema = parse_schema('any(Tensor self, *, Tensor b) -> Tensor')
     self.assertFalse(new_schema.is_backward_compatible_with(old_schema))
     # No-BC: A new schema with more arguments, appended, but no default value.
     new_schema = parse_schema(
         'any(Tensor self, *, Tensor b, int c, int d) -> Tensor')
     self.assertFalse(new_schema.is_backward_compatible_with(old_schema))
     # BC: A new schema with more arguments, appended, that have a default value.
     new_schema = parse_schema(
         'any(Tensor self, *, Tensor b, int c, int d=1) -> Tensor')
     self.assertTrue(new_schema.is_backward_compatible_with(old_schema))
     # No-BC: A new schema with more arguments, not-appended, that have a default value.
     new_schema = parse_schema(
         'any(Tensor self, int d=1, *, Tensor b, int c) -> Tensor')
     self.assertFalse(new_schema.is_backward_compatible_with(old_schema))
     # BC: A new schema where old kwargs becomes positional.
     new_schema = parse_schema(
         'any(Tensor self, Tensor b, *, int c) -> Tensor')
     self.assertTrue(new_schema.is_backward_compatible_with(old_schema))
     # BC: (the opposite case) A new schema where an old positional argument becomes kwarg.
     self.assertFalse(old_schema.is_backward_compatible_with(new_schema))
     # BC: A new schema where all old kwargs become positional.
     new_schema = parse_schema(
         'any(Tensor self, Tensor b, int c) -> Tensor')
     self.assertTrue(new_schema.is_backward_compatible_with(old_schema))
     # BC: (the opposite case) A new schema where all old positional arguments become kwarg.
     self.assertFalse(old_schema.is_backward_compatible_with(new_schema))
     # No-BC: A new schema where old kwargs appear in different order.
     new_schema = parse_schema(
         'any(Tensor self, *, int c, Tensor b) -> Tensor')
     self.assertFalse(new_schema.is_backward_compatible_with(old_schema))
     # BC: A new schema where argument becomes of type optional.
     new_schema = parse_schema(
         'any(Tensor self, *, Tensor b, int? c) -> Tensor')
     self.assertTrue(new_schema.is_backward_compatible_with(old_schema))
     # BC: A new schema where argument gains a default value.
     new_schema = parse_schema(
         'any(Tensor self, *, Tensor b, int c=1) -> Tensor')
     self.assertTrue(new_schema.is_backward_compatible_with(old_schema))
     # No-BC: A new schema where argument is "renamed".
     new_schema = parse_schema(
         'any(Tensor self, *, Tensor b, int renamed) -> Tensor')
     self.assertFalse(new_schema.is_backward_compatible_with(old_schema))
     # No-BC: A new schema where argument type changes to an incompatible type.
     new_schema = parse_schema(
         'any(Tensor self, *, Tensor b, int[] c) -> Tensor')
     self.assertFalse(new_schema.is_backward_compatible_with(old_schema))
Exemplo n.º 3
0
 def test_backward_compatible_ret(self):
     old_schema = parse_schema('any(Tensor self) -> Tensor?')
     new_schema = parse_schema('any(Tensor self) -> Tensor')
     self.assertTrue(new_schema.is_backward_compatible_with(old_schema))
     self.assertFalse(old_schema.is_backward_compatible_with(new_schema))
Exemplo n.º 4
0
 def test_schema_error(self):
     with self.assertRaisesRegex(RuntimeError, r"schemas with vararg \(...\) can't have default value args"):
         schema = parse_schema("any.foo(int arg1, int arg2=0, ...)")
Exemplo n.º 5
0
 def test_string_optional_parameter_default_value(self):
     schema_a = parse_schema("example::op(str? order=\"NCHW\") -> (Tensor)")
     schema_b = parse_schema(str(schema_a))
     self.assertEqual(schema_a, schema_b)
Exemplo n.º 6
0
 def test_forward_compatible_arguments_without_out(self):
     old_schema = parse_schema('any(Tensor self, int a, int b=1) -> Tensor')
     # deleting default arg is FC compatible
     new_schema = parse_schema('any(Tensor self, int a) -> Tensor')
     is_fc, _ = new_schema.check_forward_compatible_with(old_schema)
     self.assertTrue(is_fc)
     # adding default arg is FC compatible
     new_schema = parse_schema(
         'any(Tensor self, int a, int b=1, int c=1) -> Tensor')
     is_fc, _ = new_schema.check_forward_compatible_with(old_schema)
     self.assertTrue(is_fc)
     # adding default arg with container type is NOT FC compatible
     new_schema = parse_schema(
         'any(Tensor self, int a, int b=1, int[2] c=1) -> Tensor')
     is_fc, reason = new_schema.check_forward_compatible_with(old_schema)
     self.assertFalse(is_fc)
     self.assertEqual(
         reason,
         "Function schema is not forward compatible since the new argument"
         " \'c\' of type int[] has a container type as its default value.")
     # updating the default value of a default arg is NOT FC compatible
     new_schema = parse_schema('any(Tensor self, int a, int b=4) -> Tensor')
     is_fc, reason = new_schema.check_forward_compatible_with(old_schema)
     self.assertFalse(is_fc)
     self.assertEqual(
         reason,
         "\'b\' is not forward compatible with the older version of the schema"
     )
     # updating the arg name of a default arg is NOT FC compatible
     new_schema = parse_schema('any(Tensor self, int a, int c=1) -> Tensor')
     is_fc, reason = new_schema.check_forward_compatible_with(old_schema)
     self.assertFalse(is_fc)
     self.assertEqual(
         reason,
         "\'c\' is not forward compatible with the older version of the schema"
     )
     # not adding default arg in the end is NOT FC compatible
     new_schema = parse_schema(
         'any(Tensor self, int a, int c=1, int b=1) -> Tensor')
     is_fc, reason = new_schema.check_forward_compatible_with(old_schema)
     self.assertFalse(is_fc)
     self.assertEqual(
         reason,
         "\'c\' is not forward compatible with the older version of the schema"
     )
     # making default arg into positional arg is NOT FC compatible
     new_schema = parse_schema('any(Tensor self, int a, int b) -> Tensor')
     is_fc, reason = new_schema.check_forward_compatible_with(old_schema)
     self.assertFalse(is_fc)
     self.assertEqual(
         reason,
         "\'b\' is not forward compatible with the older version of the schema"
     )
     # making positional arg into default arg is NOT FC compatible
     new_schema = parse_schema(
         'any(Tensor self, int a=1, int b=1) -> Tensor')
     is_fc, reason = new_schema.check_forward_compatible_with(old_schema)
     self.assertFalse(is_fc)
     self.assertEqual(
         reason,
         "\'a\' is not forward compatible with the older version of the schema"
     )