Ejemplo n.º 1
0
def process_classical(ising, cl_args):
    "Write a file for classical solution and optionally run it."
    # Extract variables we need from the command-line arguments,
    format = cl_args.format
    oname = cl_args.output
    run = cl_args.run
    extra_args = cl_args.extra_args
    as_qubo = cl_args.qubo
    verbosity = cl_args.verbose
    style = cl_args.values

    # The only formats we need to process at this point are qbsolv and minizinc.
    if format == "qbsolv":
        if run:
            # Pass both user-supplied and computed arguments to qbsolv.
            args = shlex.split(extra_args)
            args.append("--verbosity=%d" % verbosity)
            args.append("--values=%s" % style)
            args.append("--pin-weight=%f" % qmasm.pin_weight)
            args.append("--chain-strength=%f" % qmasm.chain_strength)
            qmasm.run_qbsolv(ising, oname, args, verbosity)
        else:
            qmasm.write_output(ising, oname, format, as_qubo)
    elif format == "minizinc":
        if run:
            qmasm.run_minizinc(ising, oname, shlex.split(extra_args),
                               verbosity)
        else:
            qmasm.write_output(ising, oname, format, as_qubo)
Ejemplo n.º 2
0
def process_classical(ising, format, oname, run, extra_args, as_qubo,
                      verbosity):
    "Write a file for classical solution and optionally run it."
    if format == "qbsolv":
        if run:
            qmasm.run_qbsolv(ising, oname, shlex.split(extra_args), verbosity)
        else:
            qmasm.write_output(ising, oname, format, as_qubo)
    elif format == "minizinc":
        if run:
            qmasm.run_minizinc(ising, oname, shlex.split(extra_args),
                               verbosity)
        else:
            qmasm.write_output(ising, oname, format, as_qubo)
Ejemplo n.º 3
0
# As a special case, if the user specified --format=qbsolv we work with the
# pre-embedded version of the problem then exit.
if cl_args.format == "qbsolv":
    if cl_args.run:
        qmasm.run_qbsolv(logical_ising, cl_args.output,
                         shlex.split(cl_args.extra_args), cl_args.verbose)
    else:
        qmasm.write_output(logical_ising, cl_args.output, cl_args.format,
                           cl_args.qubo)
    sys.exit(0)

# As a special case, if the user specified --format=minizinc we work with the
# pre-embedded version of the problem then exit.
if cl_args.format == "minizinc":
    if cl_args.run:
        qmasm.run_minizinc(logical_ising, cl_args.output,
                           shlex.split(cl_args.extra_args), cl_args.verbose)
    else:
        qmasm.write_output(logical_ising, cl_args.output, cl_args.format,
                           cl_args.qubo)
    sys.exit(0)

# As a special case, if the user requested QMASM output we output the
# pre-embedded version of the problem.  If we weren't asked to run, we can stop
# here.
if cl_args.format == "qmasm":
    qmasm.write_output(logical_ising, cl_args.output, cl_args.format,
                       cl_args.qubo)
    if not cl_args.run:
        sys.exit(0)

# Embed the problem onto the D-Wave.