Reference
GadgetSearch.EnergyModel — Type
EnergyModelAbstract type for energy models. Subtypes define how energy is computed from vertex states.
GadgetSearch.Gadget — Type
Gadget{M<:EnergyModel, T<:Real}A gadget found by the search algorithm.
Type Parameters
M: Energy model type (RydbergModel or QUBOModel)T: Numeric type for weights
Fields
constraint::GadgetConstraint: The constraint this gadget satisfiesgraph::SimpleGraph{Int}: The graph structurepins::Vector{Int}: Pin vertex indicesvertex_weights::Vector{T}: Vertex weights (hᵢ)edge_weights::Vector{T}: Edge weights (Jᵢⱼ), empty for RydbergModeledge_list::Vector{Tuple{Int,Int}}: Edge list corresponding to edge_weightspos::Union{Nothing, Vector{Tuple{Float64, Float64}}}: Vertex positions
GadgetSearch.GadgetConstraint — Type
GadgetConstraintAbstract type for gadget constraints. Subtypes define what ground states are required.
GadgetSearch.QUBOModel — Type
QUBOModel <: EnergyModelEnergy model for general QUBO (Quadratic Unconstrained Binary Optimization).
- State space: All 2^n binary configurations
- Energy: E(σ) = Σᵢ hᵢσᵢ + Σ₍ᵢ,ⱼ₎ Jᵢⱼσᵢσⱼ (vertex + edge weights)
GadgetSearch.RydbergModel — Type
RydbergModel <: EnergyModelEnergy model for Rydberg atom systems.
- State space: Maximal Independent Sets (MIS)
- Energy: E(σ) = Σᵢ hᵢσᵢ (vertex weights only)
GadgetSearch.TruthTableConstraint — Type
TruthTableConstraint <: GadgetConstraintConstraint defined by a truth table (for Rydberg/MIS-based gadgets).
Fields
truth_table::BitMatrix: Truth table where each row is a ground state configuration on pins
GadgetSearch.UnweightedGadget — Type
UnweightedGadgetResult of an unweighted gadget search (Definition 3.6 / Theorem 3.7 in the paper).
Fields
pattern_graph::SimpleGraph{Int}: The target graph Rreplacement_graph::SimpleGraph{Int}: The candidate graph R' that replaces Rboundary_vertices::Vector{Int}: Boundary vertices ofreplacement_graphconstant_offset::Float64: Constant offset between the reduced alpha tensors ofpattern_graphandreplacement_graphpos::Union{Nothing, Vector{Tuple{Float64, Float64}}}: Vertex positions ofreplacement_graph
GadgetSearch._find_weights — Function
_find_weights(::Type{RydbergModel}, ...) -> Union{Nothing, Vector{Float64}}Find vertex weights for Rydberg model.
GadgetSearch._find_weights — Function
_find_weights(::Type{QUBOModel}, ...) -> Union{Nothing, Tuple{Vector{Float64}, Vector{Float64}}}Find vertex and edge weights for QUBO model.
GadgetSearch._graph_hash — Method
_graph_hash(g::SimpleGraph{Int}) -> UInt64Create a hash for graph structure for caching purposes.
GadgetSearch._solve_weights_sampled — Method
_solve_weights_sampled(...)Optimized version for large combination spaces using random sampling.
GadgetSearch.calculate_alpha_tensor — Method
calculate_alpha_tensor(graph, boundary_vertices)Compute the alpha tensor of a graph with given boundary vertices using tropical tensor network contraction.
The alpha tensor alpha(R) is a rank-|boundary| tensor where each element alpha(R)_s is the size of the largest independent set of R with boundary vertices fixed to configuration s, or -Inf if s violates the independent set constraint.
Arguments
graph::SimpleGraph{Int}: The graph Rboundary_vertices::Vector{Int}: The boundary vertex indices (1-indexed)
Returns
Array{<:Tropical}: Tropical tensor of shape(2, 2, ..., 2)withlength(boundary_vertices)dimensions
GadgetSearch.calculate_reduced_alpha_tensor — Method
calculate_reduced_alpha_tensor(graph, boundary_vertices)Compute the reduced alpha tensor α̃(R) of a graph with given boundary vertices.
The reduced alpha tensor is obtained by applying mis_compactify! to the alpha tensor: a boundary configuration s is set to -Inf if there exists a subset configuration s' ⊆ s (fewer boundary vertices selected) that achieves an equal or better MIS size. This removes dominated configurations, leaving only the "essential" boundary behaviors.
Arguments
graph::SimpleGraph{Int}: The graph Rboundary_vertices::Vector{Int}: The boundary vertex indices (1-indexed)
Returns
Array{<:Tropical}: Reduced tropical tensor of shape(2, 2, ..., 2)
GadgetSearch.check_connectivity_after_removal — Method
check_connectivity_after_removal(graph, vertices_to_remove)Check if a graph remains connected after removing specified vertices.
GadgetSearch.check_gadget — Method
check_gadget(gadget::Gadget; _return_info::Bool=false, model::Type{<:EnergyModel}=RydbergModel)Validate a Gadget by computing energies for its state space and reporting the ground state configurations on pins.
Arguments
gadget::Gadget: The gadget to check.
Keyword Arguments
_return_info::Bool=false: Iftrue, return a string; otherwise log with@info.model::Type{<:EnergyModel}=RydbergModel: Energy model to use for validation.
Returns
- When
_return_infoistrue, returns a formattedString; otherwise returnsnothing.
GadgetSearch.check_gadget_qubo — Method
check_gadget_qubo(gadget::Gadget; _return_info::Bool=false)Check gadget using QUBO (full state space) model.
GadgetSearch.check_gadget_rydberg — Method
check_gadget_rydberg(gadget::Gadget; _return_info::Bool=false)Check gadget using Rydberg (MIS) model.
GadgetSearch.clear_cache! — Method
clear_cache!()Clear the MIS cache to free memory. Useful for long-running processes.
GadgetSearch.complete_graph — Method
complete_graph(n::Int) -> SimpleGraphCreate a complete graph with n vertices where every pair of vertices is connected.
Arguments
n: Number of vertices
Returns
SimpleGraph: The complete graph K_n
GadgetSearch.find_matching_gadget — Method
find_matching_gadget(loader; filter=nothing, limit=nothing, keys_range=nothing, max_results=nothing)Find gadgets matching a given filter function from the graph loader.
GadgetSearch.find_maximal_independent_sets — Method
find_maximal_independent_sets(g)Find all maximal independent sets of a graph using bit masks with caching.
GadgetSearch.generate_full_grid_graph — Method
generate_full_grid_graph(lattice::LatticeType, nx::Int, ny::Int; path::String="grid.g6") -> StringGenerate complete graphs on a grid lattice (without boundary expansion) and save to file. All vertices are connected to each other, regardless of distance.
Arguments
lattice: Type of lattice (Square or Triangular) - determines physical positionsnx: Number of grid points in x directionny: Number of grid points in y directionpath: Output file path for saving graphs (default: "grid.g6")
Returns
String: Path to the saved graph file
Details
Generates a single complete graph on the nx×ny grid. The physical positions follow the lattice geometry, but edges connect all pairs of vertices.
GadgetSearch.generate_full_grid_udg — Method
generate_full_grid_udg(lattice::LatticeType, nx::Int, ny::Int; path::String="udg.g6") -> StringGenerate unit disk graphs on a grid lattice with four boundary pins and save to file.
Arguments
lattice: Type of lattice (Square or Triangular)nx: Number of inner positions in x directionny: Number of inner positions in y directionpath: Output file path for saving graphs (default: "udg.g6")
Returns
String: Path to the saved graph file
Details
Generates all possible UDGs by placing pins on boundary positions and connecting vertices within unit distance on the specified lattice type.
GadgetSearch.get_cache_stats — Method
get_cache_stats()Get statistics about the MIS cache usage.
GadgetSearch.get_state_space — Method
get_state_space(::Type{QUBOModel}, graph::SimpleGraph{Int}) -> Tuple{Vector{UInt32}, Int}Get the state space for QUBO model (all 2^n states).
GadgetSearch.get_state_space — Method
get_state_space(::Type{RydbergModel}, graph::SimpleGraph{Int}) -> Tuple{Vector{UInt32}, Int}Get the state space for Rydberg model (Maximal Independent Sets).
GadgetSearch.is_diff_by_constant — Method
is_diff_by_constant(t1, t2)Check whether two reduced alpha tensors differ by a constant (Theorem 3.7 in the paper).
Two gadgets R and R' are valid MIS replacements if and only if their reduced alpha tensors differ only by a constant offset. This function tests that condition.
Returns (true, c) if t1[i] - t2[i] == c for all finite entries, and both tensors have -Inf at exactly the same positions. Returns (false, 0) otherwise.
Callers must ensure that at least one tensor has a finite entry (i.e., not all-Inf).
Arguments
t1::AbstractArray{T}: First reduced alpha tensor (finite values or-Inf)t2::AbstractArray{T}: Second reduced alpha tensor (finite values or-Inf)
Returns
Tuple{Bool, Real}:(is_valid, constant_offset)
GadgetSearch.is_gadget_replacement — Method
is_gadget_replacement(g1, g2, open_vertices1, open_vertices2)Check whether gadget g2 (with boundary open_vertices2) is a valid MIS replacement for gadget g1 (with boundary open_vertices1), i.e., their reduced alpha tensors differ only by a constant (Theorem 3.7 in the paper).
Returns
Tuple{Bool, Real}:(is_valid, constant_offset)whereconstant_offset = α̃(g2) - α̃(g1)
GadgetSearch.make_filter — Method
make_filter(model_type, constraint, optimizer, env; kwargs...)Create a filter closure for graph search that checks if a graph can implement the given constraint.
Arguments
model_type::Type{<:EnergyModel}: RydbergModel or QUBOModelconstraint::GadgetConstraint: The target constraint to implementoptimizer: Optimization solver for weight findingenv: Environment for the optimizer
Keywords
connected::Bool=false: Whether to require connected graphs onlyobjective=nothing: Objective function for optimizationallow_defect::Bool=false: Whether to allow zero vertex weightsmax_samples::Int=1000: Maximum samples for enumerationpin_candidates::Union{Nothing, Vector{Vector{Int}}}=nothing: Candidate pin combinationscheck_connectivity::Bool=true: Whether to check graph connectivity
Returns
Function: Filter function that takes (graph, pos, pin_set) and returns Gadget or nothing
GadgetSearch.make_unweighted_filter — Method
make_unweighted_filter(target_graph, target_boundary)Create a filter closure for unweighted gadget search.
Pre-computes α̃(target_graph) once, then returns a closure that checks each candidate graph by trying all boundary vertex combinations of the same size.
Arguments
target_graph::SimpleGraph{Int}: The pattern graph Rtarget_boundary::Vector{Int}: Boundary vertices of R
Returns
Function: Closure(candidate, pos, pin_set) -> UnweightedGadget | nothing
GadgetSearch.match_constraint_to_states — Method
match_constraint_to_states(states, constraint, pin_set)Match constraint ground states to full graph states based on pin configuration.
Returns
Vector{Vector{Int}}: For each ground state pattern, indices of matching states in the state space
GadgetSearch.search_by_truth_tables — Method
search_by_truth_tables(loader, truth_tables; kwargs...)Search for Rydberg gadgets by truth tables (legacy interface).
GadgetSearch.search_gadgets — Method
search_gadgets(model_type, loader, constraints; kwargs...)Unified search function for both Rydberg and QUBO gadgets.
Arguments
model_type::Type{<:EnergyModel}: RydbergModel or QUBOModelloader::GraphLoader: The graph loader containing candidate graphsconstraints::Vector{<:GadgetConstraint}: Constraints to search for
Keywords
optimizer: Optimization solver to use for weight findingenv=nothing: Environment for the optimizerconnected::Bool=false: Whether to require connected graphs onlyobjective=nothing: Objective function for optimizationallow_defect::Bool=false: Whether to allow zero vertex weightslimit=nothing: Maximum number of graphs to searchmax_samples::Int=100: Maximum samples for weight enumerationsave_path::String="results.json": Path to save intermediate resultspin_candidates::Union{Nothing, Vector{Vector{Int}}}=nothing: Candidate pin combinationscheck_connectivity::Bool=true: Whether to check graph connectivitymax_result_num::Int=1: Maximum number of results per constraint
Returns
Tuple{Vector{Vector{Gadget}}, Vector{<:GadgetConstraint}}: Found gadgets grouped by constraint and failed constraints
GadgetSearch.search_unweighted_gadgets — Method
search_unweighted_gadgets(target_graph, target_boundary, loader; limit, max_results)Search for unweighted gadget replacements of target_graph by iterating over a GraphLoader.
For each candidate graph, tries all boundary vertex combinations of size length(target_boundary) and checks if the reduced alpha tensors differ by a constant (Theorem 3.7). Returns on the first valid boundary found per candidate.
Arguments
target_graph::SimpleGraph{Int}: The pattern graph Rtarget_boundary::Vector{Int}: Boundary vertices of Rloader::GraphLoader: Graph dataset to search over
Keywords
limit::Union{Int,Nothing}=nothing: Maximum number of graphs to examinemax_results::Union{Int,Nothing}=nothing: Stop after finding this many results
Returns
Vector{UnweightedGadget}
GadgetSearch.solve_weights — Method
solve_weights(model_type, states, target_indices_all, graph, pin_set, optimizer; kwargs...)Unified weight solver that works for both Rydberg and QUBO models.
GadgetSearch.unit_disk_graph — Method
unit_disk_graph(locs::AbstractVector, unit::Real) -> SimpleGraphCreate a unit disk graph from given locations. Two vertices are connected if their Euclidean distance is less than the unit distance.
Arguments
locs: Vector of vertex locationsunit: Unit distance threshold for edge creation
Returns
SimpleGraph: The constructed unit disk graph