Ejemplo n.º 1
0
# Solve poisson's equation by `scipy.sparse.linalg.splu`
# and `scipy.sparse.linagl.spsolve`.
A = poisson.getA().toarray()
b = poisson.getRHS()
print(f"A:\n{A}")
print(f"b:\n{b}")

lu = sp.linalg.splu(A)
x_lu = lu.solve(b)
x = sp.linalg.spsolve(A, b)
if not np.all(np.isclose(x_lu, x)):
    raise ArithmeticError

# Show result
mesh.plot_image(x)
plt.title("Solved by `scipy.sparse.linalg.spsolve`")
print(f"x:\n{x}")

# Solve Poisson's equation using Quantum Annealing (Direct QPU).
# Construct a DirectSolver instance
solver = bl_lstsq.DirectSolver(A, b)

# Set sampler and parameters for DirectSolver.solve method
sampler = EmbeddingComposite(
    DWaveSampler(solver={'qpu': True},
                 postprocess="sampling"))  # use postprocess
# sampler = SimulatedAnnealingSampler()
sampling_params = {
    "num_reads": 1000,
    "chain_strength": 100,
Ejemplo n.º 2
0
norm_bins = np.arange(num_discrete_value) + 0.5
norm_bins = np.insert(norm_bins, 0, np.min(norm_bins) - 1.0)
cbar_ticklabels = np.array([low_param_value, high_param_value])
norm = mpl.colors.BoundaryNorm(norm_bins, num_discrete_value, clip=True)
formatter = mpl.ticker.FuncFormatter(lambda x, pos: cbar_ticklabels[norm(x)])
cbar_ticks = norm_bins[:-1] + (norm_bins[1:] - norm_bins[:-1]) / 2

models = [bin_model_params, result["bin_model_params"]]
titles = ["Synthetic Resistivity Model", "Predicted Resistivity Model"]
for i in range(2):
    fig = plt.figure(figsize=(9, 4))
    ax1 = fig.add_axes([0.14, 0.17, 0.68, 0.7])
    im = mesh.plot_image(models[i],
                         ax=ax1,
                         grid=False,
                         pcolor_opts={
                             "norm": norm,
                             "cmap": cmap
                         })
    ax1.set_title(titles[i])
    ax1.set_xlabel("x (m)")
    ax1.set_ylabel("z (m)")
    ax2 = fig.add_axes([0.84, 0.17, 0.03, 0.7])
    cbar = fig.colorbar(im[0], cax=ax2, format=formatter, ticks=cbar_ticks)
    cbar.set_label(r"$\rho$ ($\Omega$*m)", rotation=270, labelpad=15, size=12)
mpl.rcdefaults()

# Compare predicted and observed responses
pred_resp = dwinv.utils.fwd_modeling(fwd_model, result["bin_model_params"],
                                     (low_param_value, high_param_value))
with np.printoptions(precision=8, suppress=True):