コード例 #1
0
ファイル: qmasm.py プロジェクト: ucdavis/qmasm
cl_args = qmasm.parse_command_line()

# Specify the minimum distinguishable difference between energy readings.
min_energy_delta = 0.005

# Parse the original input file(s) into an internal representation.
qmasm.parse_files(cl_args.input)

# Parse the variable pinnings specified on the command line.  Append these to
# the program.
if cl_args.pin != None:
    for pin in cl_args.pin:
        qmasm.program.extend(qmasm.process_pin("[command line]", 1, pin))

# Walk the statements in the program, processing each in turn.
logical_either = qmasm.Problem(cl_args.qubo)
for stmt in qmasm.program:
    stmt.update_qmi("", logical_either)

# Store all tallies for later reportage.
logical_stats = {
    "vars": qmasm.next_sym_num + 1,
    "strengths": len(logical_either.strengths),
    "eqs": len(logical_either.chains),
    "pins": len(logical_either.pinned)
}

# Convert from QUBO to Ising in case the solver doesn't support QUBO problems.
if cl_args.qubo:
    logical_ising = logical_either.convert_to_ising()
else:
コード例 #2
0
    sys.stderr.write("# %s\n" % line)
    if bits_re.match(line):
        bits = [int(b) for b in list(line)]
    elif b"Energy of solution" in line:
        energy = float(line.split()[0])
retcode = proc.wait()
if retcode < 0:
    os.kill(os.getpid(), -retcode)
elif retcode > 0:
    # Some qbsolv errors go to stdout, not stderr.
    for line in proc.stdout:
        sys.stderr.write("qbsolv: %s\n" % line)
    sys.exit(retcode)
sys.stderr.write("\n")

# Fake various QMASM objects.
qmasm.pin_weight = pin_weight
qmasm.chain_strength = chain_strength
for n, q in sorted(name2qubit.items(), key=lambda k: k[1]):
    qmasm.sym_map.new_symbol(n)
answer = {"num_occurrences": [1],
          "energies": [energy],
          "solutions": [[2*b - 1 for b in bits]]}
problem = qmasm.Problem(False)
problem.embedding = [[i] for i in range(len(bits))]
problem.embedder_chains = set()
solutions = qmasm.Solutions(answer, problem, verbosity >= 2)

# Output the solution.  For now, we hard-wire show_asserts to False.
qmasm.output_solution(solutions, style, verbosity, False)