Esempio n. 1
0
                     len(physical.strengths))
    sys.stderr.write("    Physical    Chains        %5d\n" %
                     len(physical.chains))
    sys.stderr.write("\n")

    # Output some additional chain statistics.
    chain_lens = [len(c) for c in physical.embedding]
    max_chain_len = 0
    if chain_lens != []:
        max_chain_len = max(chain_lens)
    num_max_chains = len([l for l in chain_lens if l == max_chain_len])
    sys.stderr.write("    Maximum chain length = %d (occurrences = %d)\n\n" %
                     (max_chain_len, num_max_chains))

# Manually scale the weights and strengths so Qubist doesn't complain.
physical = qmasm.scale_weights_strengths(physical, cl_args.verbose)

# Output a file in any of a variety of formats.  Note that we've already
# handled qbsolv output and QMASM output as special cases.
if cl_args.format != "qmasm" and (cl_args.output != "<stdout>"
                                  or not cl_args.run):
    qmasm.write_output(physical, cl_args.output, cl_args.format, cl_args.qubo)

# If we weren't told to run anything we can exit now.
if not cl_args.run:
    sys.exit(0)

# Submit the problem to the D-Wave.
if cl_args.verbose >= 1:
    sys.stderr.write("Submitting the problem to the %s solver.\n\n" %
                     qmasm.solver_name)
Esempio n. 2
0
                     len(physical_ising.strengths))
    sys.stderr.write("    Physical    Chains        %5d\n" %
                     len(physical_ising.chains))
    sys.stderr.write("\n")

    # Output some additional chain statistics.
    chain_lens = [len(c) for c in physical_ising.embedding]
    max_chain_len = 0
    if chain_lens != []:
        max_chain_len = max(chain_lens)
    num_max_chains = len([l for l in chain_lens if l == max_chain_len])
    sys.stderr.write("    Maximum chain length = %d (occurrences = %d)\n\n" %
                     (max_chain_len, num_max_chains))

# Manually scale the weights and strengths so Qubist doesn't complain.
physical_ising = qmasm.scale_weights_strengths(physical_ising, cl_args.verbose)

# Process all classical solvers.  If we're here and the solver is classical,
# then always_embed must be True.
if cl_args.format in classical_solvers:
    qmasm.process_classical(physical_ising, cl_args.format, cl_args.output,
                            cl_args.run, cl_args.extra_args, cl_args.qubo,
                            cl_args.verbose)
    sys.exit(0)

# Output a file in any of a variety of formats.  Note that a few cases
# were handled above by process_classical.
if write_output_file:
    if cl_args.format == "qmasm":
        # Don't write a QMASM file if we already did so before embedding.
        pass