Skip to content

Make CTG MinConflictsSolver deterministic #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Timmmm
Copy link
Contributor

@Timmmm Timmmm commented Feb 3, 2025

Draft because I haven't tested this at all yet, and the Python code doesn't have types so we can't rely on that.

Description

python-constraints now allows you to pass a PRNG to MinConflictsSolve which allows it to be deterministic. Version 2.0 is also apparently several orders of magnitude faster.

Related Issues

riscv-software-src/riscv-ctg#115

@jamesbeyond jamesbeyond added the size-S Small efforts required label Feb 24, 2025
@allenjbaum
Copy link
Collaborator

any estimate when this can be ready for merge? This will become increasingly important in the sort to medium term.

python-constraints now allows you to pass a PRNG to MinConflictsSolve which allows it to be deterministic. Version 2.0 is also apparently several orders of magnitude faster.
@Timmmm
Copy link
Contributor Author

Timmmm commented Mar 24, 2025

I tried to test it but unfortunately it looks like the code is already broken at the moment:

❯ riscv_isac normalize -x 64 -f 64 --cgf-file coverage/dataset.cgf --cgf-file coverage/cgfs_fext/RV32D/fmsub.d.cgf -o normalized_fmsub.d.cgf
    INFO | ****** RISC-V ISA Coverage 0.18.0 *******
    INFO | Copyright (c) 2020, InCore Semiconductors Pvt. Ltd.
    INFO | All Rights Reserved.
Traceback (most recent call last):
  File "/home/codasip.com/timothy.hutt/workspace/riscv-arch-test/riscv-venv/bin/riscv_isac", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/codasip.com/timothy.hutt/workspace/riscv-arch-test/riscv-venv/lib64/python3.12/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/codasip.com/timothy.hutt/workspace/riscv-arch-test/riscv-venv/lib64/python3.12/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/codasip.com/timothy.hutt/workspace/riscv-arch-test/riscv-venv/lib64/python3.12/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/codasip.com/timothy.hutt/workspace/riscv-arch-test/riscv-venv/lib64/python3.12/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/codasip.com/timothy.hutt/workspace/riscv-arch-test/riscv-venv/lib64/python3.12/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: normalize() missing 2 required positional arguments: 'header_file' and 'cgf_macro'

The problem is here:

@cli.command(help = "Normalize the cgf.")
@click.option(
        '--cgf-file','-c',multiple=True,
        type=click.Path(resolve_path=True,readable=True,exists=True),
        help="Coverage Group File(s). Multiple allowed.",required=True
    )
@click.option(
        '--output-file','-o',
        type=click.Path(writable=True,resolve_path=True),
        help="Coverage Group File",
        required = True
    )
@click.option('--xlen','-x',type=click.Choice(['32','64']),default='32',help="XLEN value for the ISA.")
@click.option('--flen','-f',type=click.Choice(['32','64']),default='32',help="FLEN value for the ISA.")
@click.option('--log-redundant',
        is_flag = True,
        help = "Log redundant coverpoints during normalization"
)
def normalize(cgf_file,output_file,xlen,flen,log_redundant,header_file,cgf_macro):
    logger.info("Writing normalized CGF to "+str(output_file))
    with open(output_file,"w") as outfile:
        utils.dump_yaml(preprocessing(Translate_cgf(expand_cgf(cgf_file,int(xlen),int(flen),log_redundant)), header_file, cgf_macro),outfile)

The extra header_file and cgf_macro options were added without corresponding CLI parameters.

This sort of thing is why I highly recommend using static type annotations and things that work well with them (Typer in this case). One of the many benefits is that it catches silly mistakes like these.

Looks like this bug is from here.

@Timmmm Timmmm force-pushed the deterministic_constraint branch from 6392cb3 to 0cc12eb Compare March 24, 2025 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size-S Small efforts required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants