def METHOD_NAME(m, modules, leaves):
    logger.debug(f'gen_constraints_for_module: {m["concrete_name"]}')
    pog_constraints = []
    for instance in m['instances']:
        iname = instance['instance_name']
        ctn = instance['concrete_template_name']
        constraints = None
        # I don't know why I have to do this: I can't check to see if 'constraints' is in leaves[ctn] (it never is.)
        if ctn in leaves:
            try:
                constraints = leaves[ctn]['constraints']
            except KeyError:
                pass
        elif ctn in modules:
            try:
                constraints = modules[ctn]['constraints']
            except KeyError:
                pass
        else:
            assert False, f'{ctn} not found in leaves or modules.'
        place_on_grid_constraints = []
        if constraints is not None:
            new_constraints = [constraint.dict() if type(constraint) != dict else constraint for constraint in constraints]
            place_on_grid_constraints = [constraint for constraint in new_constraints if constraint['constraint'] == 'PlaceOnGrid']
        tr = instance['transformation']
        for pog in place_on_grid_constraints:
            if pog['direction'] == 'H':
                s, o = tr['sY'], tr['oY']
            elif pog['direction'] == 'V':
                s, o = tr['sX'], tr['oX']
            else:
                assert False, pog['direction']
            new_ored_terms = []
            for ored_term in pog['ored_terms']:
                for offset, scaling in product(ored_term['offsets'], ored_term['scalings']):
                    new_offset = (offset-s*o*scaling) % pog['pitch']
                    new_scaling = s*scaling
                    new_ored_terms.append(OffsetsScalings(offsets=[new_offset],scalings=[new_scaling]))
            pog_constraints.append(PlaceOnGrid(direction=pog['direction'], pitch=pog['pitch'], ored_terms=new_ored_terms))
    if pog_constraints:
        m['constraints'].extend(cnst.dict() for cnst in split_directions_and_merge(*pog_constraints))
        logger.debug(f"{m}")