From c8fad326ecc95b93d08a72e564982b035e82947e Mon Sep 17 00:00:00 2001 From: Jinguo Liu Date: Thu, 1 Aug 2024 01:14:55 +0800 Subject: [PATCH] Upgrade dependencies (#672) * upgrade luxor graph plot * upgrade all dependencies * fix ci * fix tests --- .ci/src/main.jl | 20 +- .github/workflows/CI.yml | 1 - Project.toml | 2 +- lib/BloqadeCUDA/Project.toml | 4 +- lib/BloqadeExpr/Project.toml | 4 +- lib/BloqadeKrylov/Project.toml | 2 +- lib/BloqadeLattices/Project.toml | 2 +- lib/BloqadeLattices/src/BloqadeLattices.jl | 1 + lib/BloqadeLattices/src/visualize.jl | 388 +++++++++++---------- lib/BloqadeLattices/test/visualize.jl | 4 +- lib/BloqadeMIS/Project.toml | 2 +- lib/BloqadeNoisy/Project.toml | 2 +- lib/BloqadeNoisy/src/problem.jl | 12 +- lib/BloqadeODE/Project.toml | 6 +- lib/BloqadeQMC/Project.toml | 2 +- lib/BloqadeSchema/Project.toml | 8 +- lib/BloqadeSchema/src/execute.jl | 2 +- lib/YaoSubspaceArrayReg/Project.toml | 4 +- 18 files changed, 246 insertions(+), 220 deletions(-) diff --git a/.ci/src/main.jl b/.ci/src/main.jl index f0a21ad72..6d0e35895 100644 --- a/.ci/src/main.jl +++ b/.ci/src/main.jl @@ -162,15 +162,21 @@ develop the Bloqade components into environment. end function collect_lib_deps(path::String) - libs = readdir(root_dir("lib")) - d = TOML.parsefile(root_dir(path, "Project.toml")) - names = [name for name in keys(d["deps"]) if name in libs || name == "Bloqade"] - paths = map(names) do name - name == "Bloqade" && return "." - return root_dir("lib", name) - end + paths = unique!(collect_lib_deps_recur!(path, String[])) pkgs = map(paths) do path return Pkg.PackageSpec(; path = root_dir(path)) end return pkgs end + +function collect_lib_deps_recur!(path::String, paths::Vector{String}) + libs = readdir(root_dir("lib")) + d = TOML.parsefile(root_dir(path, "Project.toml")) + names = [name for name in keys(d["deps"]) if name in libs || name == "Bloqade"] + map(names) do name + subpath = name == "Bloqade" ? "." : root_dir("lib", name) + push!(paths, subpath) + collect_lib_deps_recur!(subpath, paths) + end + return paths +end diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 03255d829..37b319bd0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -35,7 +35,6 @@ jobs: fail-fast: false matrix: version: - - '1.6' - '1' os: - ubuntu-latest diff --git a/Project.toml b/Project.toml index 82de76abe..6e7e7c19c 100644 --- a/Project.toml +++ b/Project.toml @@ -31,7 +31,7 @@ ForwardDiff = "0.10" Measurements = "2" PythonCall = "0.8,0.9" Reexport = "1" -Yao = "0.8" +Yao = "0.9" YaoSubspaceArrayReg = "0.2" julia = "1.6.3" diff --git a/lib/BloqadeCUDA/Project.toml b/lib/BloqadeCUDA/Project.toml index e0893f3ac..9f734addc 100644 --- a/lib/BloqadeCUDA/Project.toml +++ b/lib/BloqadeCUDA/Project.toml @@ -9,8 +9,8 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] -Adapt = "3" -CUDA = "3" +Adapt = "4" +CUDA = "5" julia = "1.6" [extras] diff --git a/lib/BloqadeExpr/Project.toml b/lib/BloqadeExpr/Project.toml index 8a0197a93..90a32e8be 100644 --- a/lib/BloqadeExpr/Project.toml +++ b/lib/BloqadeExpr/Project.toml @@ -21,8 +21,8 @@ YaoAPI = "0843a435-28de-4971-9e8b-a9641b2983a8" YaoBlocks = "418bc28f-b43b-5e0b-a6e7-61bbc1a2c1df" [compat] -Adapt = "3" -BitBasis = "0.8" +Adapt = "4" +BitBasis = "0.9" BloqadeLattices = "0.2" ForwardDiff = "0.10" LaTeXStrings = "1" diff --git a/lib/BloqadeKrylov/Project.toml b/lib/BloqadeKrylov/Project.toml index fc6da524c..ebcb1eff2 100644 --- a/lib/BloqadeKrylov/Project.toml +++ b/lib/BloqadeKrylov/Project.toml @@ -16,7 +16,7 @@ YaoArrayRegister = "e600142f-9330-5003-8abb-0ebd767abc51" YaoSubspaceArrayReg = "bd27d05e-4ce1-5e79-84dd-c5d7d508ade2" [compat] -Adapt = "3" +Adapt = "4" BloqadeExpr = "0.2.1" BloqadeLattices = "0.2" BloqadeWaveforms = "0.2" diff --git a/lib/BloqadeLattices/Project.toml b/lib/BloqadeLattices/Project.toml index d0318f991..974a84e9f 100644 --- a/lib/BloqadeLattices/Project.toml +++ b/lib/BloqadeLattices/Project.toml @@ -11,7 +11,7 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" [compat] LinearAlgebra = "1.6" -LuxorGraphPlot = "0.2" +LuxorGraphPlot = "0.5" NearestNeighbors = "0.4" StatsBase = "0.33, 0.34" UnicodePlots = "3.6" diff --git a/lib/BloqadeLattices/src/BloqadeLattices.jl b/lib/BloqadeLattices/src/BloqadeLattices.jl index 525162b38..4b8a33eca 100644 --- a/lib/BloqadeLattices/src/BloqadeLattices.jl +++ b/lib/BloqadeLattices/src/BloqadeLattices.jl @@ -8,6 +8,7 @@ using StatsBase using LuxorGraphPlot using LuxorGraphPlot: Point using LuxorGraphPlot.Luxor: Colors +import LuxorGraphPlot.Luxor using LinearAlgebra import Base.deleteat! diff --git a/lib/BloqadeLattices/src/visualize.jl b/lib/BloqadeLattices/src/visualize.jl index bcf78e905..1dddaae4a 100644 --- a/lib/BloqadeLattices/src/visualize.jl +++ b/lib/BloqadeLattices/src/visualize.jl @@ -4,20 +4,19 @@ const DEFAULT_NODE_COLOR = Ref("transparent") const DEFAULT_BACKGROUND_COLOR = Ref("transparent") const CONFIGHELP = """ -### Extra Keyword Arguments +##### general * `background_color = DEFAULT_BACKGROUND_COLOR[]` -* `scale::Float64 = 1` is a multiplicative factor to rescale the atom distance for better visualization +* `scale::Int = 60.0` is the number of pixels per unit length * `xpad::Float64 = 2.5` is the padding space in x axis * `ypad::Float64 = 1.5` is the padding space in y axis -* `unit::Int = 60` is the number of pixel per unit distance ##### axes * `axes_text_color = DEFAULT_TEXT_COLOR[]` * `axes_text_fontsize::Float64 = 16.0` * `axes_num_of_xticks = 5` * `axes_num_of_yticks = 5` -* `axes_x_offset::Float64 = 0.1` -* `axes_y_offset::Float64 = 0.06` +* `axes_x_offset::Float64 = 0.5` +* `axes_y_offset::Float64 = 0.5` * `axes_unit::String = "μm"` ##### node @@ -31,9 +30,9 @@ const CONFIGHELP = """ * `bond_color = DEFAULT_LINE_COLOR[]` * `bond_linewidth::Float64 = 1.0` -##### `blockade` +##### blockade * `blockade_radius::Float64=0`, atoms within `blockade_radius` will be connected by edges. -* `blockade_style::String = "none"` +* `blockade_style::String = "none"`, can be "none" or "dashed" * `blockade_stroke_color = DEFAULT_LINE_COLOR[]` * `blockade_fill_color = "transparent"` * `blockade_fill_opacity::Float64 = 0.5` @@ -50,57 +49,99 @@ const CONFIGHELP = """ * `grid_stroke_style::String="dashed"` """ +Base.@kwdef mutable struct AxisDisplayConfig + axes_text_color::String = DEFAULT_TEXT_COLOR[] + axes_text_fontsize::Float64 = 16.0 + axes_num_of_xticks::Int = 5 + axes_num_of_yticks::Int = 5 + axes_x_offset::Float64 = 0.5 + axes_y_offset::Float64 = 0.5 + axes_unit::String = "μm" +end -function config_plotting(sites, xpad, ypad) - xmin, ymin, xmax, ymax = LuxorGraphPlot.get_bounding_box(sites) +""" + LatticeDisplayConfig - # compute the shortest distance - n = length(sites) - if n <= 1 - shortest_distance = 1.0 - else - shortest_distance = Inf - for i in 1:n - for j in i+1:n - shortest_distance = min(sqrt(sum(abs2, sites[i] .- sites[j])), shortest_distance) - end - end - end - scale = 1/shortest_distance - xpad = xpad === nothing ? (xmax - xmin) * 0.2 + shortest_distance : xpad - ypad = ypad === nothing ? (ymax - ymin) * 0.2 + shortest_distance : ypad - axes_x_offset = 0.5 * xpad - axes_y_offset = 0.4 * ypad - - axes_num_of_yticks = ceil(Int, min((ymax - ymin + 1e-5)*scale, 5)) - axes_num_of_xticks = ceil(Int, min((xmax - xmin + 1e-5)*scale, 5)) - return (; - scale, - xpad, ypad, - axes_x_offset, - axes_y_offset, - axes_num_of_xticks, - axes_num_of_yticks, - ) +The configuration for lattice display. + +### Fields +$CONFIGHELP +""" +Base.@kwdef struct LatticeDisplayConfig + # line, node and text + background_color = DEFAULT_BACKGROUND_COLOR[] + scale::Float64 = 60.0 + xpad::Float64 = 2.5 + ypad::Float64 = 1.5 + + # axes + axes_text_color = DEFAULT_LINE_COLOR[] # NOTE: follow the line color! + axes_text_fontsize::Float64 = 16.0 + axes_num_of_xticks::Int = 5 + axes_num_of_yticks::Int = 5 + axes_x_offset::Float64 = 0.5 + axes_y_offset::Float64 = 0.5 + axes_unit::String = "μm" + + # node + node_size::Float64 = 0.2 + node_text_fontsize::Float64 = 16.0 + node_text_color = DEFAULT_TEXT_COLOR[] + node_stroke_color = DEFAULT_LINE_COLOR[] + node_stroke_linewidth::Float64 = 1.0 # in pt + node_fill_color = DEFAULT_NODE_COLOR[] + + # bond + bond_color = DEFAULT_LINE_COLOR[] + bond_linewidth::Float64 = 1.0 # in pt + + # blockade + blockade_style::String = "none" + blockade_stroke_color = DEFAULT_LINE_COLOR[] + blockade_fill_color = "transparent" + blockade_fill_opacity::Float64 = 0.5 + blockade_stroke_linewidth::Float64 = 1.0 + blockade_radius::Float64 = 0.0 + + # arrow + arrow_linewidth::Float64=1.0 # in pt + arrow_head_length::Float64=6.0 + arrow_color=DEFAULT_LINE_COLOR[] + + # grid + grid_stroke_color="#AAAAAA" + grid_stroke_width::Float64=1 + grid_stroke_style::String="dashed" +end +function extract_atom_graph_display_config(config::LatticeDisplayConfig) + GraphDisplayConfig(; background=config.background_color, fontsize=config.node_text_fontsize, + vertex_shape=:circle, vertex_line_width=config.node_stroke_linewidth, vertex_line_style="solid", + vertex_text_color=config.node_text_color, vertex_stroke_color=config.node_stroke_color, vertex_color=config.node_fill_color, + vertex_size=config.node_size * config.scale, edge_color=config.bond_color, edge_line_width=config.bond_linewidth, edge_line_style="solid") +end +function extract_blockade_graph_display_config(config::LatticeDisplayConfig) + GraphDisplayConfig(; background=config.background_color, fontsize=config.node_text_fontsize, + vertex_shape=:circle, vertex_line_width=config.blockade_stroke_linewidth, vertex_line_style="dashed", + vertex_text_color=config.node_text_color, vertex_stroke_color=config.blockade_stroke_color, vertex_color=config.blockade_fill_color, + vertex_size=config.blockade_radius * config.scale, edge_color=config.bond_color, edge_line_width=config.bond_linewidth, edge_line_style="solid") +end +function extract_axis_display_config(config::LatticeDisplayConfig) + AxisDisplayConfig(; axes_text_color=config.axes_text_color, axes_text_fontsize=config.axes_text_fontsize, + axes_num_of_xticks=config.axes_num_of_xticks, axes_num_of_yticks=config.axes_num_of_yticks, + axes_x_offset=config.axes_x_offset, axes_y_offset=config.axes_y_offset, axes_unit=config.axes_unit) end + """ - img_atoms(atoms::AtomList; - colors = [DEFAULT_LINE_COLOR[], ...], - texts = ["1", "2", ...], - vectors = [], - format = :svg, - filename = nothing, - kwargs... - ) - img_atoms(bounded_lattice::BoundedLattice; - colors = [DEFAULT_LINE_COLOR[], ...], - texts = ["1", "2", ...], - vectors = [], - format = :svg, - filename = nothing, - kwargs... + img_atoms(atoms::Union{AtomList, BoundedLattice}; + colors = [DEFAULT_LINE_COLOR[], ...], + texts = ["1", "2", ...], + vectors = [], + format = :svg, + filename = nothing, + kwargs... ) + Plots `atoms` or `bounded_lattice.site_positions` with colors specified by `colors` and texts specified by `texts`. You will need a `VSCode`, `Pluto` notebook or `Jupyter` notebook to show the image. If you want to write this image to the disk without displaying it in a frontend, please try @@ -110,9 +151,12 @@ julia> img_atoms(generate_sites(SquareLattice(), 5, 5); filename="test.png") ``` ### Keyword Arguments +##### features * `colors` is a vector of colors for nodes * `texts` is a vector of string displayed on nodes * `vectors` is a vector of (start_loc, end_loc) pair to specify a list of arrows. + +##### IO * `format` can be `:svg`, `:pdf` or `:png` * `filename` can be a filename string with suffix `.svg`, `.png` or `.pdf` @@ -120,37 +164,43 @@ $CONFIGHELP """ function img_atoms( atoms::AtomList{2}; + # vertex features colors = nothing, texts = nothing, vectors = [], - xpad=nothing, - ypad=nothing, + # IO format = :svg, filename = nothing, - kwargs..., + # config + kwargs... ) - length(atoms) == 0 && return LuxorGraphPlot._draw(()->nothing, 100, 100; format, filename) - - xmin, ymin, xmax, ymax = LuxorGraphPlot.get_bounding_box(atoms) - auto = config_plotting(atoms, xpad, ypad) - config = LatticeDisplayConfig(; auto..., kwargs...) - Dx, Dy = ((xmax-xmin)+2*auto.xpad)*config.scale*config.unit, ((ymax-ymin)+2*auto.ypad)*config.scale*config.unit - transform(loc) = config.scale .* (loc[1]-xmin+auto.xpad, loc[2]-ymin+auto.ypad) - LuxorGraphPlot._draw(Dx, Dy; format, filename) do - LuxorGraphPlot.background(config.background_color) - _viz_atoms(transform.(atoms), _edges(atoms, config.blockade_radius), - colors, map(ab->transform.(ab), vectors), texts, config) - _viz_axes(; transform, xmin, ymin, xmax, ymax, - axes_x_offset=config.axes_x_offset, axes_y_offset=config.axes_y_offset, - axes_num_of_xticks=config.axes_num_of_xticks, axes_num_of_yticks=config.axes_num_of_yticks, - axes_text_fontsize=config.axes_text_fontsize, axes_text_color=config.axes_text_color, axes_unit=config.axes_unit, unit=config.unit) + length(atoms) == 0 && return LuxorGraphPlot.with_nodes(()->nothing, NodeStore(); format, filename) + + # config + config = LatticeDisplayConfig(; kwargs...) + + xpad, ypad = config.xpad * config.scale, config.ypad * config.scale + nodestore() do ns + for atom in atoms + circle!(ns, atom .* config.scale, max(config.node_size, config.blockade_radius) * config.scale) + end + with_nodes(ns; format, filename, + padding_bottom = ypad, + padding_left = xpad, + padding_right = xpad, + padding_top = ypad, + background = config.background_color + ) do + _viz_atoms(atoms, colors, vectors, texts, config) + xmin, xmax, ymin, ymax = minimum(a->a[1], atoms), maximum(a->a[1], atoms), minimum(a->a[2], atoms), maximum(a->a[2], atoms) + _viz_axes(xmin-config.xpad/2, xmax+config.xpad/2, ymin-config.ypad/2, ymax+config.ypad/2, config.scale, extract_axis_display_config(config)) + end end end img_atoms(atoms::AtomList{1}; kwargs...) = img_atoms(padydim(atoms); kwargs...) img_atoms(bounded_lattice::BoundedLattice{<:AbstractLattice{2},<:AbstractRegion{2}}; kwargs...) = img_atoms(bounded_lattice.site_positions; kwargs...) img_atoms(bounded_lattice::BoundedLattice{<:AbstractLattice{1},<:AbstractRegion{1}}; kwargs...) = img_atoms(bounded_lattice.site_positions; kwargs...) - function _edges(atoms, blockade_radius) n = length(atoms) edges = Tuple{Int,Int}[] @@ -163,98 +213,57 @@ function _edges(atoms, blockade_radius) end _LinRange(x, y, n) = n > 1 ? LinRange(x, y, n) : (x + y) / 2 -function _viz_axes(; transform, xmin, xmax, ymin, ymax, - axes_num_of_xticks, axes_num_of_yticks, axes_text_fontsize, axes_text_color, axes_unit, unit, - axes_x_offset, axes_y_offset - ) +function _viz_axes(xmin, xmax, ymin, ymax, scale, config::AxisDisplayConfig) # the true coordinates - xs = _LinRange(xmin, xmax, axes_num_of_xticks) - ys = _LinRange(ymin, ymax, axes_num_of_yticks) - coo(x, y) = Point(transform((x, y)))*unit + xs = _LinRange(xmin, xmax, config.axes_num_of_xticks) + ys = _LinRange(ymin, ymax, config.axes_num_of_yticks) + coo(x, y) = Point((x, y)) * scale xys = [xs..., ys...] # the display coordinates of axes labels - locs = [[coo(x, ymax+axes_y_offset) for x in xs]..., - [coo(xmin-axes_x_offset, y) for y in ys]...] - for (x, loc) in zip(xys, locs) - LuxorGraphPlot.draw_text(loc, "$(round(x; digits=2))$(axes_unit)"; - color=axes_text_color, fontsize=axes_text_fontsize*unit/60, fontface="") + locs = [[coo(x, ymax+config.axes_y_offset) for x in xs]..., + [coo(xmin-config.axes_x_offset, y) for y in ys]...] + Luxor.@layer begin + Luxor.sethue(config.axes_text_color) + Luxor.fontsize(config.axes_text_fontsize) + for (x, loc) in zip(xys, locs) + Luxor.text("$(round(x; digits=2))$(config.axes_unit)", loc) + end end end -Base.@kwdef struct LatticeDisplayConfig - # line, node and text - background_color = DEFAULT_BACKGROUND_COLOR[] - scale::Float64 = 1.0 - xpad::Float64 = 2.5 - ypad::Float64 = 1.5 - unit::Int = 60 - - # axes - axes_text_color = DEFAULT_LINE_COLOR[] # NOTE: follow the line color! - axes_text_fontsize::Float64 = 16.0 - axes_num_of_xticks::Int = 5 - axes_num_of_yticks::Int = 5 - axes_x_offset::Float64 = 0.1 - axes_y_offset::Float64 = 0.06 - axes_unit::String = "μm" - - # node - node_size::Float64 = 0.25 - node_text_fontsize::Float64 = 16.0 - node_text_color = DEFAULT_TEXT_COLOR[] - node_stroke_color = DEFAULT_LINE_COLOR[] - node_stroke_linewidth::Float64 = 1.0 # in pt - node_fill_color = DEFAULT_NODE_COLOR[] - - # bond - bond_color = DEFAULT_LINE_COLOR[] - bond_linewidth::Float64 = 1.0 # in pt - - # blockade - blockade_style::String = "none" - blockade_stroke_color = DEFAULT_LINE_COLOR[] - blockade_fill_color = "transparent" - blockade_fill_opacity::Float64 = 0.5 - blockade_stroke_linewidth::Float64 = 1.0 - blockade_radius::Float64 = 0.0 - - # arrow - arrow_linewidth::Float64=1.0 # in pt - arrow_head_length::Float64=6.0 - arrow_color="black" - - # grid - grid_stroke_color="#AAAAAA" - grid_stroke_width::Float64=1 - grid_stroke_style::String="dashed" -end - -function _viz_atoms(locs, edges, colors, vectors, texts, config) +function _viz_atoms(atoms, colors, vectors, texts, config::LatticeDisplayConfig) # show the blockade if config.blockade_style != "none" - blockadeconfig = LuxorGraphPlot.GraphDisplayConfig(; vertex_stroke_color=config.blockade_stroke_color, vertex_line_width=config.blockade_stroke_linewidth, - vertex_fill_color=Colors.RGBA(LuxorGraphPlot.sethue(config.blockade_fill_color)..., config.blockade_fill_opacity), - vertex_size=config.blockade_style=="half" ? config.blockade_radius/2 : config.blockade_radius, - vertex_line_style="dashed", - xpad=config.xpad, ypad=config.ypad, xpad_right=config.xpad, ypad_bottom=config.ypad, - #vertex_stroke_opacity=config.blockade_fill_opacity, - unit=config.unit) - LuxorGraphPlot.unitless_show_graph(locs, Tuple{Int,Int}[], nothing, nothing, nothing, nothing, nothing, nothing, texts, blockadeconfig) + blockade_config = extract_blockade_graph_display_config(config) + nodes = [LuxorGraphPlot.circlenode(atom .* config.scale, blockade_config.vertex_size) for atom in atoms] + LuxorGraphPlot.render_nodes(nodes, blockade_config; + texts = nothing, + vertex_colors=nothing, + vertex_stroke_colors=nothing, + vertex_text_colors=nothing, + ) end # show the arrows - for v in vectors - LuxorGraphPlot.draw_edge(Point(v[1])*config.unit, Point(v[2])*config.unit; color=config.arrow_color, line_width=config.arrow_linewidth, - arrow=true, arrowheadlength=config.arrow_head_length, line_style="solid") + Luxor.@layer begin + Luxor.sethue(config.arrow_color) + Luxor.setline(config.arrow_linewidth) + Luxor.setdash("solid") + for v in vectors + Luxor.arrow(Point(v[1]) * config.scale, Point(v[2]) * config.scale; arrowheadlength=config.arrow_head_length) + end end - # show the graph - graphconfig = LuxorGraphPlot.GraphDisplayConfig(; vertex_stroke_color=config.node_stroke_color, vertex_line_width=config.node_stroke_linewidth, - vertex_size=config.node_size, vertex_fill_color=config.node_fill_color, - vertex_text_color=config.node_text_color, fontsize=config.node_text_fontsize, - xpad=config.xpad, ypad=config.ypad, xpad_right=config.xpad, ypad_bottom=config.ypad, - edge_color=config.bond_color, edge_line_width=config.bond_linewidth, unit=config.unit) - LuxorGraphPlot.unitless_show_graph(locs, edges, colors, nothing, nothing, nothing, nothing, nothing, texts, graphconfig) + # show the atoms and edges + edges = _edges(atoms, config.blockade_radius) + atoms_config = extract_atom_graph_display_config(config) + atoms_diag = LuxorGraphPlot.diagram(map(a->a .* config.scale, atoms), edges; config=atoms_config) + LuxorGraphPlot.show_diagram(atoms_diag; config=extract_atom_graph_display_config(config), texts, + vertex_colors=colors, + vertex_stroke_colors=nothing, + vertex_text_colors=nothing, + edge_colors=nothing + ) end struct ByDensity @@ -299,9 +308,12 @@ Draw a `maskedgrid` with colors specified by `colors` and texts specified by `te You will need a `VSCode`, `Pluto` notebook or `Jupyter` notebook to show the image. ### Keyword Arguments +##### features * `colors` is a vector of colors for nodes * `texts` is a vector of string displayed on nodes -* `vectors` is a vector of arrows +* `vectors` is a vector of (start_loc, end_loc) pair to specify a list of arrows. + +##### IO * `format` can be `:svg`, `:pdf` or `:png` * `filename` can be a filename string with suffix `.svg`, `.png` or `.pdf` @@ -309,48 +321,58 @@ $CONFIGHELP """ function img_maskedgrid( maskedgrid::MaskedGrid; - format = :svg, - filename = nothing, + # features colors = nothing, texts = nothing, vectors = [], - xpad = nothing, - ypad = nothing, + # IO + format = :svg, + filename = nothing, kwargs..., ) + # config + config = LatticeDisplayConfig(; kwargs...) + xpad, ypad = config.xpad * config.scale, config.ypad * config.scale + atoms = padydim(collect_atoms(maskedgrid)) - xmin, ymin, xmax, ymax = LuxorGraphPlot.get_bounding_box(atoms) - auto = config_plotting(atoms, xpad, ypad) - - config = LatticeDisplayConfig(; auto..., kwargs...) - Dx, Dy = ((xmax-xmin)+2*auto.xpad)*config.scale*config.unit, ((ymax-ymin)+2*auto.ypad)*config.scale*config.unit - transform(loc) = config.scale .* (loc[1]-xmin+auto.xpad, loc[2]-ymin+auto.ypad) - LuxorGraphPlot._draw(Dx, Dy; format, filename) do - LuxorGraphPlot.background(config.background_color) - # show the grid - _viz_grid(maskedgrid.xs, maskedgrid.ys; transform, unit=config.unit, auto.xpad, auto.ypad, xmin, ymin, - xmax, ymax, - color=config.grid_stroke_color, line_width=config.grid_stroke_width, line_style=config.grid_stroke_style) - # show atoms - length(atoms) > 0 && _viz_atoms(transform.(atoms), _edges(atoms, config.blockade_radius), - colors, vectors, texts, config) - # show the axes - _viz_axes(; transform, xmin, ymin, xmax, ymax, - axes_x_offset=config.axes_x_offset, axes_y_offset=config.axes_y_offset, - axes_num_of_xticks=config.axes_num_of_xticks, axes_num_of_yticks=config.axes_num_of_yticks, - axes_text_fontsize=config.axes_text_fontsize, axes_text_color=config.axes_text_color, axes_unit=config.axes_unit, unit=config.unit) + nodestore() do ns + for atom in atoms + circle!(ns, atom .* config.scale, max(config.node_size, config.blockade_radius) * config.scale) + end + with_nodes(ns; format, filename, + padding_bottom = ypad, + padding_left = xpad, + padding_right = xpad, + padding_top = ypad, + background = config.background_color + ) do + + # show the grid + xmin, xmax, ymin, ymax = minimum(a->a[1], atoms), maximum(a->a[1], atoms), minimum(a->a[2], atoms), maximum(a->a[2], atoms) + _viz_grid(maskedgrid.xs, maskedgrid.ys; scale=config.scale, config.xpad, config.ypad, xmin, ymin, + xmax, ymax, + color=config.grid_stroke_color, line_width=config.grid_stroke_width, line_style=config.grid_stroke_style) + length(atoms) > 0 && _viz_atoms(atoms, colors, vectors, texts, config) + _viz_axes(xmin-config.xpad/2, xmax+config.xpad/2, ymin-config.ypad/2, ymax+config.ypad/2, config.scale, extract_axis_display_config(config)) + end end end -function _viz_grid(xs, ys; transform, xpad, ypad, unit, xmin, ymin, xmax, ymax, color, line_width, line_style) +function _viz_grid(xs, ys; xpad, ypad, scale, xmin, ymin, xmax, ymax, color, line_width, line_style) _xmin, _xmax = (xmin - 0.3*xpad, xmax + 0.3*xpad) _ymin, _ymax = (ymin - 0.3*ypad, ymax + 0.3*ypad) - coo(x, y) = Point(transform((x, y)))*unit - for x in xs - LuxorGraphPlot.draw_edge(coo(x, _ymin), coo(x, _ymax); color, line_width, line_style) - end - for y in ys - LuxorGraphPlot.draw_edge(coo(_xmin, y), coo(_xmax, y); color, line_width, line_style) + coo(x, y) = Point((x, y)) * scale + Luxor.@layer begin + Luxor.sethue(color) + Luxor.setline(line_width) + Luxor.setdash(line_style) + for x in xs + Luxor.line(coo(x, _ymin), coo(x, _ymax)) + end + for y in ys + Luxor.line(coo(_xmin, y), coo(_xmax, y)) + end + Luxor.strokepath() end end @@ -376,13 +398,11 @@ end function darktheme!() DEFAULT_LINE_COLOR[] = "#FFFFFF" DEFAULT_TEXT_COLOR[] = "#FFFFFF" - #DEFAULT_NODE_COLOR[] = "#000000" end function lighttheme!() DEFAULT_LINE_COLOR[] = "#000000" DEFAULT_TEXT_COLOR[] = "#000000" - #DEFAULT_NODE_COLOR[] = "#FFFFFF" end function Base.show(io::IO, mime::MIME"text/plain", atoms::AtomList) diff --git a/lib/BloqadeLattices/test/visualize.jl b/lib/BloqadeLattices/test/visualize.jl index 3e338a999..8823a0591 100644 --- a/lib/BloqadeLattices/test/visualize.jl +++ b/lib/BloqadeLattices/test/visualize.jl @@ -14,11 +14,11 @@ using Documenter @test img_atoms(lt; colors = nothing) isa LuxorGraphPlot.Drawing @test img_atoms(lt; node_fill_color = "red") isa LuxorGraphPlot.Drawing @test img_atoms(lt; colors = fill("blue", length(lt))) isa LuxorGraphPlot.Drawing - @test img_atoms(lt; colors = ByDensity(randn(length(lt)); vmax = 10)) isa LuxorGraphPlot.Drawing + @test img_atoms(lt; colors = ByDensity(rand(0:10, length(lt)); vmax = 10)) isa LuxorGraphPlot.Drawing @test img_atoms(blt; colors = nothing) isa LuxorGraphPlot.Drawing @test img_atoms(blt; node_fill_color = "red") isa LuxorGraphPlot.Drawing @test img_atoms(blt; colors = fill("blue", length(lt))) isa LuxorGraphPlot.Drawing - @test img_atoms(blt; colors = ByDensity(randn(length(lt)); vmax = 10)) isa LuxorGraphPlot.Drawing + @test img_atoms(blt; colors = ByDensity(rand(0:10, length(lt)); vmax = 10)) isa LuxorGraphPlot.Drawing @test img_maskedgrid(grd) isa LuxorGraphPlot.Drawing @test show(IOBuffer(), MIME"image/svg+xml"(), grd) === nothing @test show(IOBuffer(), MIME"image/svg+xml"(), lt) === nothing diff --git a/lib/BloqadeMIS/Project.toml b/lib/BloqadeMIS/Project.toml index c51c9928e..d62f87512 100644 --- a/lib/BloqadeMIS/Project.toml +++ b/lib/BloqadeMIS/Project.toml @@ -17,7 +17,7 @@ YaoArrayRegister = "e600142f-9330-5003-8abb-0ebd767abc51" YaoSubspaceArrayReg = "bd27d05e-4ce1-5e79-84dd-c5d7d508ade2" [compat] -BitBasis = "0.8" +BitBasis = "0.9" BloqadeExpr = "0.2" BloqadeLattices = "0.2" EliminateGraphs = "0.2" diff --git a/lib/BloqadeNoisy/Project.toml b/lib/BloqadeNoisy/Project.toml index b31c43c02..196d24666 100644 --- a/lib/BloqadeNoisy/Project.toml +++ b/lib/BloqadeNoisy/Project.toml @@ -25,7 +25,7 @@ BloqadeExpr = "0.2" BloqadeODE = "0.2" BloqadeWaveforms = "0.2" DiffEqBase = "6" -DiffEqCallbacks = "2" +DiffEqCallbacks = "3" JSON = "0.21" Kronecker = "0.5" OrdinaryDiffEq = "6" diff --git a/lib/BloqadeNoisy/src/problem.jl b/lib/BloqadeNoisy/src/problem.jl index 5c8a82084..875aa4c22 100644 --- a/lib/BloqadeNoisy/src/problem.jl +++ b/lib/BloqadeNoisy/src/problem.jl @@ -433,11 +433,11 @@ over the series of save times. """ function simulation_series_mean(sim; index=false) ntraj = length(sim) - times = length(sim[1]) + times = length(sim[:, 1]) if index == false - [mean([sim[i][t] for i in 1:ntraj]) for t in 1:times] + [mean([sim[t, i] for i in 1:ntraj]) for t in 1:times] else - [mean([sim[i][t][index] for i in 1:ntraj]) for t in 1:times] + [mean([sim[t, i][index] for i in 1:ntraj]) for t in 1:times] end end @@ -453,11 +453,11 @@ Convenience method to estimate the sampling error in the ensemble solution """ function simulation_series_err(sim; index=false, factor=2) ntraj = length(sim) - times = length(sim[1]) + times = length(sim[:, 1]) if index == false - [factor * std([sim[i][t] for i in 1:ntraj]) / sqrt(ntraj) for t in 1:times] + [factor * std([sim[t, i] for i in 1:ntraj]) / sqrt(ntraj) for t in 1:times] else - [factor * std([sim[i][t][index] for i in 1:ntraj]) / sqrt(ntraj) for t in 1:times] + [factor * std([sim[t, i][index] for i in 1:ntraj]) / sqrt(ntraj) for t in 1:times] end end diff --git a/lib/BloqadeODE/Project.toml b/lib/BloqadeODE/Project.toml index 337a4c835..1d7a40784 100644 --- a/lib/BloqadeODE/Project.toml +++ b/lib/BloqadeODE/Project.toml @@ -21,18 +21,18 @@ YaoArrayRegister = "e600142f-9330-5003-8abb-0ebd767abc51" YaoSubspaceArrayReg = "bd27d05e-4ce1-5e79-84dd-c5d7d508ade2" [compat] -Adapt = "3" +Adapt = "4" BloqadeExpr = "0.2" BloqadeKrylov = "0.2" BloqadeMIS = "0.2" BloqadeWaveforms = "0.2" Configurations = "0.17" DiffEqBase = "6" -DiffEqCallbacks = "2" +DiffEqCallbacks = "3" OrdinaryDiffEq = "6" Reexport = "1" SciMLBase = "2" -Yao = "0.8" +Yao = "0.9" YaoArrayRegister = "0.9" YaoSubspaceArrayReg = "0.2" julia = "1.6" diff --git a/lib/BloqadeQMC/Project.toml b/lib/BloqadeQMC/Project.toml index 4b75662a0..f650cc321 100644 --- a/lib/BloqadeQMC/Project.toml +++ b/lib/BloqadeQMC/Project.toml @@ -39,7 +39,7 @@ OnlineStats = "1" PushVectors = "0.2" RandomNumbers = "1.4" Statistics = "1" -Yao = "0.8" +Yao = "0.9" julia = "1.6" [extras] diff --git a/lib/BloqadeSchema/Project.toml b/lib/BloqadeSchema/Project.toml index dfa7deea0..3e0e4572d 100644 --- a/lib/BloqadeSchema/Project.toml +++ b/lib/BloqadeSchema/Project.toml @@ -20,12 +20,12 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c" [compat] -AWS = "1.78" -BitBasis = "0.8" +AWS = "1" +BitBasis = "0.9" BloqadeExpr = "0.2" BloqadeODE = "0.2" BloqadeWaveforms = "0.2" -Braket = "0.7, 0.8" +Braket = "0.9" Configurations = "0.17" DecFP = "1.1" GarishPrint = "0.5" @@ -33,7 +33,7 @@ JSON = "0.21" OrderedCollections = "1.5" Roots = "2" Unitful = "1" -Yao = "0.8" +Yao = "0.9" julia = "1.6" [extras] diff --git a/lib/BloqadeSchema/src/execute.jl b/lib/BloqadeSchema/src/execute.jl index e62956d30..720f31a5a 100644 --- a/lib/BloqadeSchema/src/execute.jl +++ b/lib/BloqadeSchema/src/execute.jl @@ -51,7 +51,7 @@ function execute(task::QuEraTaskSpecification) reg = zero_state(n_atoms) problem = SchrodingerProblem(reg, total_time, h) BloqadeExpr.emulate!(problem) - bitstrings = reg |> measure(; nshots=task.nshots) + bitstrings = reg |> BloqadeExpr.measure(; nshots=task.nshots) return JSON.json(Configurations.to_dict(to_task_output(bitstrings))) end diff --git a/lib/YaoSubspaceArrayReg/Project.toml b/lib/YaoSubspaceArrayReg/Project.toml index 286409a59..358b44f1e 100644 --- a/lib/YaoSubspaceArrayReg/Project.toml +++ b/lib/YaoSubspaceArrayReg/Project.toml @@ -14,8 +14,8 @@ YaoArrayRegister = "e600142f-9330-5003-8abb-0ebd767abc51" YaoBlocks = "418bc28f-b43b-5e0b-a6e7-61bbc1a2c1df" [compat] -Adapt = "3" -BitBasis = "0.8" +Adapt = "4" +BitBasis = "0.8, 0.9" BloqadeExpr = "0.2" StatsBase = "0.33, 0.34" YaoAPI = "0.4"