예제 #1
0
파일: cmdline.py 프로젝트: CIDARLAB/pyMINT
def convert_to_parchmint(
    input_file: Path,
    outpath: Path,
    skip_constraints: bool = True,
    generate_graph_view: bool = False,
):
    """
    Convert a .mint file to a .parchmint.json file
    """
    extension = input_file.suffix
    if extension == ".mint" or extension == ".uf":
        current_device = MINTDevice.from_mint_file(str(input_file),
                                                   skip_constraints)

        # Save the device parchmint v1_2 to a file
        parchmint_text = current_device.to_parchmint()

        # Create new file in outpath with the same name as the current device
        outpath.mkdir(parents=True, exist_ok=True)
        with open(str(outpath.joinpath(input_file.stem + ".json")), "w") as f:
            print("Writing to file: {}".format(f.name))

            json.dump(parchmint_text, f, indent=4)

        # Generate a graph view of the device
        if generate_graph_view:
            printgraph(current_device.device.graph, current_device.device.name)
    else:
        raise Exception("Unsupported file extension: {}".format(extension))
예제 #2
0
파일: primitive.py 프로젝트: CIDARLAB/pyLFR
    def get_default_netlist(self, cn_id: str,
                            name_gen: NameGenerator) -> MINTDevice:
        """Returns the default netlist for the primitive

        Args:
            cn_id (str): ID of the construction node so that we can prefix the id's of all the components that are part of the default netlist
            name_gen (NameGenerator): A namegenerator instance that is used for the globally for synthesizing the design

        Returns:
            MINTDevice: Default netlist of whatever the primitive is
        """
        if self.type is not PrimitiveType.NETLIST:
            raise Exception(
                "Cannot execute this method for this kind of a  primitive")

        default_mint_file = parameters.LIB_DIR.joinpath(
            self._default_netlist).resolve()

        device = MINTDevice.from_mint_file(str(default_mint_file))

        if device is None:
            raise Exception(
                "Unable to parse MINT file: {} for construction node {}".
                format(str(default_mint_file), cn_id))
        name_gen.rename_netlist(cn_id, device)
        # Return the default netlist
        return device
예제 #3
0
def test_mirror_test4():
    mint_file = "tests/mint_files/mirror_test4.mint"
    mint_device = MINTDevice.from_mint_file(mint_file)
    # Convert it to Parchmint
    parchmint_device = mint_device.to_parchmint()
    # Write the Parchmint to a file
    with open(mint_file.replace(".mint", ".json"), "r") as data_file:
        text = data_file.read()
        device_json = json.loads(text)
        assert ordered(parchmint_device) == ordered(device_json)
예제 #4
0
def test_node_test2():
    mint_file = "tests/mint_files/node_test2.mint"
    mint_device = MINTDevice.from_mint_file(mint_file)
    # Convert it to Parchmint
    parchmint_device = mint_device.to_parchmint()
    # Write the Parchmint to a file
    with open(mint_file.replace(".mint", ".json"), "r") as data_file:
        text = data_file.read()
        device_json = json.loads(text)
        assert parchmint_device == device_json
예제 #5
0
def main():

    # parameters.PROGRAM_DIR = os.path.abspath(os.path.dirname(__file__))

    parser = argparse.ArgumentParser()

    parser.add_argument('input',
                        help="This is the file thats used as the input ")
    parser.add_argument('--outpath',
                        type=str,
                        default="out/",
                        help="This is the output directory")
    parser.add_argument(
        '-c',
        '--convert',
        action='store_true',
        help='Sets the flag to only convert the design and nothing else')

    args = parser.parse_args()

    ascii_banner = pyfiglet.figlet_format("Fluigi")
    print(ascii_banner)

    print("output dir:", args.outpath)
    print("Running File: " + args.input)

    extension = Path(args.input).suffix
    if extension != '.mint' and extension != '.uf':
        print("Unrecognized file Extension")
        exit()

    abspath = Path(args.outpath).resolve()
    parameters.OUTPUT_DIR = abspath

    if os.path.isdir(abspath) is not True:
        print("Creating the output directory:")
        path = Path(parameters.OUTPUT_DIR)
        path.mkdir(parents=True)

    #Check if the device netlist is planar
    current_device = MINTDevice.from_mint_file(args.input)
    graph = current_device.G

    if nx.algorithms.check_planarity(graph) == False:
        print('Error - Non-planar graph seen')
        sys.exit(0)

    try:
        pull_defaults(current_device)
        pull_dimensions(current_device)
    except Exception as e:
        print('Error getting Primitive data: {}'.format(e))

    layout = Layout()
    layout.importMINTwithoutConstraints(current_device)

    pull_defaults(current_device)
    pull_dimensions(current_device)
    pull_terminals(current_device)
    generateSpringLayout(layout)

    layout.applyLayout()

    tt = os.path.join(parameters.OUTPUT_DIR,
                      '{}_no_par.json'.format(current_device.name))
    with open(tt, 'w') as f:
        json.dump(current_device.to_parchmint_v1(), f)

    print(current_device.G.edges)

    utils.printgraph(current_device.G, current_device.name + '.dot')

    # We exit the process if only convert is set to true
    if args.convert:
        sys.exit(0)

    layout = Layout()
    layout.importMINTwithoutConstraints(current_device)

    #Do Terminal Assignment
    assign_single_port_terminals(current_device)

    # #Generate the Simulated Annealing Layout
    # generate_simulated_annealing_layout_v2(current_device)
    # generate_simulated_annealing_layout(layout)

    # generateSpectralLayout(layout)
    generateHOLALayout(layout)
    layout.applyLayout()
    layout.ensureLegalCoordinates()
    layout.print_layout()

    tt = os.path.join(parameters.OUTPUT_DIR,
                      '{}_hola_par.json'.format(current_device.name))
    with open(tt, 'w') as f:
        json.dump(current_device.to_parchmint_v1(), f)

    utils.printgraph(layout.G, current_device.name + '.layout.dot')