Skip to content

Commit 593783a

Browse files
committed
Replaced gensym with UUIDs
1 parent 8c93ff6 commit 593783a

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1818
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1919
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2020
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
21+
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
2122

2223
[compat]
2324
Graphs = "1"

src/Plasmo.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using Graphs
1717
using Printf
1818
using Distributed
1919
using DistributedArrays
20+
using UUIDs
2021

2122
using MathOptInterface
2223
const MOI = MathOptInterface

src/aggregate.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ end
6767
### Aggregate Functions
6868

6969
"""
70-
aggregate(graph::OptiGraph; name=gensym())
70+
aggregate(graph::OptiGraph; name=Symbol(UUIDs.uuid4()))
7171
7272
Aggregate an optigraph into a graph containing a single optinode. An optional
7373
`name` can be used to name the new optigraph.
7474
Returns the new optinode (which points to a new graph with `source_graph(node)`) and a
7575
mapping from the original graph variables and constraints to the new node variables and
7676
constraints.
7777
"""
78-
function aggregate(graph::OptiGraph; name=gensym())
78+
function aggregate(graph::OptiGraph; name=Symbol(UUIDs.uuid4()))
7979
# aggregate into a graph containing a single optinode
8080
new_graph = OptiGraph(; name=name)
8181
new_node, ref_map = _copy_graph_elements_to!(new_graph, graph)
@@ -388,7 +388,7 @@ how many levels of subgraphs remain in the new aggregated optigraph. For example
388388
Return a new aggregated optigraph and reference map that maps elements from the old
389389
optigraph to the new aggregate optigraph.
390390
"""
391-
function aggregate_to_depth(graph::OptiGraph, max_depth::Int64=0; name=gensym())
391+
function aggregate_to_depth(graph::OptiGraph, max_depth::Int64=0; name=Symbol(UUIDs.uuid4()))
392392
if num_subgraphs(graph) == 0
393393
error("`aggregate_to_depth` requires the graph to contain subgraphs.")
394394
end

src/backends/moi_backend.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ end
357357
function MOI.set(
358358
backend::GraphMOIBackend, attr::MOI.UserDefinedFunction, node::OptiNode, args...
359359
)
360-
registered_name = Symbol(gensym(), node.label, ".", attr.name)
360+
registered_name = Symbol(Symbol(UUIDs.uuid4()), node.label, ".", attr.name)
361361
MOI.set(
362362
backend.moi_backend, MOI.UserDefinedFunction(registered_name, attr.arity), args...
363363
)
@@ -367,7 +367,7 @@ end
367367

368368
# TODO: set operator on graph directly
369369
function MOI.set(backend::GraphMOIBackend, attr::MOI.UserDefinedFunction, args...)
370-
registered_name = Symbol(gensym(), backend.optigraph.label, ".", attr.name)
370+
registered_name = Symbol(Symbol(UUIDs.uuid4()), backend.optigraph.label, ".", attr.name)
371371
MOI.set(
372372
backend.moi_backend, MOI.UserDefinedFunction(registered_name, attr.arity), args...
373373
)

src/distributed/core_types.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ const RemoteOptiRef = Union{
199199
A constructor function for building a RemoteOptiGraph. The actual optigraph object of the
200200
RemoteOptiGraph object is stored on the worker `worker`. A name can be passed as a keyword argument
201201
"""
202-
function RemoteOptiGraph(; name::Symbol=Symbol(:rg, gensym()), worker::Int=1)
202+
function RemoteOptiGraph(; name::Symbol=Symbol(:rg, Symbol(UUIDs.uuid4())), worker::Int=1)
203203
if !(worker in procs())
204204
error("The provided worker $worker is not in existing workers: $(procs())")
205205
end
206-
darray = distribute([OptiGraph(name=name)], procs=[worker]) #gensym may not return a symbol that is unique on the worker...
206+
darray = distribute([OptiGraph(name=name)], procs=[worker])
207207
rgraph = RemoteOptiGraph(
208208
worker,
209209
darray,

src/distributed/optinode.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ function add_node(rgraph::RemoteOptiGraph)
8282

8383
f = @spawnat wid begin
8484
lgraph = localpart(darray)[1]
85-
# I think gensym is only unique to the worker, so we
86-
# tack on the worker id to ensure it is globally unique
87-
n = add_node(lgraph; index=Symbol(gensym(), ".w$wid"))
85+
n = add_node(lgraph; index=Symbol(UUIDs.uuid4()))
8886
_convert_local_to_proxy(lgraph, n)
8987
end
9088
pnode = fetch(f)

src/optigraph.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function _initialize_optigraph(name::Symbol)
2121
return graph
2222
end
2323

24-
function OptiGraph(; name::Symbol=Symbol(:g, gensym()))
24+
function OptiGraph(; name::Symbol=Symbol(:g, Symbol(UUIDs.uuid4())))
2525
graph = _initialize_optigraph(name)
2626
# default is to use a CachingOptimizer backend
2727
graph.backend = cached_moi_backend(graph)
@@ -30,7 +30,7 @@ end
3030

3131
function direct_moi_graph(
3232
backend::Union{MOI.ModelLike,MOI.OptimizerWithAttributes};
33-
name::Symbol=Symbol(:g, gensym()),
33+
name::Symbol=Symbol(:g, Symbol(UUIDs.uuid4())),
3434
)
3535
graph = _initialize_optigraph(name)
3636
graph.backend = direct_moi_backend(graph, backend)
@@ -49,7 +49,7 @@ function Base.string(graph::OptiGraph)
4949
%16s %9s %16s
5050
%16s %9s %16s
5151
""",
52-
"$(name(graph))",
52+
"",
5353
"#local elements",
5454
"#total elements",
5555
"Nodes:",
@@ -180,7 +180,7 @@ Add a new optinode to `graph`. By default, the node label is set to be "n<i+1>"
180180
the number of nodes in the graph.
181181
"""
182182
function add_node(
183-
graph::OptiGraph; label=Symbol(graph.label, Symbol(".n"), length(graph.optinodes) + 1), index = gensym()
183+
graph::OptiGraph; label=Symbol(graph.label, Symbol(".n"), length(graph.optinodes) + 1), index = Symbol(UUIDs.uuid4())
184184
)
185185
node_index = NodeIndex(index)
186186
node = OptiNode(Ref(graph), node_index, Ref(label))
@@ -461,19 +461,19 @@ end
461461
# manage subgraphs
462462

463463
"""
464-
add_subgraph(graph::OptiGraph; name::Symbol=Symbol(:sg,gensym()))
464+
add_subgraph(graph::OptiGraph; name::Symbol=Symbol(:sg, Symbol(UUIDs.uuid4())))
465465
466466
Create and add a new subgraph to the optigraph `graph`.
467467
"""
468-
function add_subgraph(graph::OptiGraph; name::Symbol=Symbol(:sg, gensym()))
468+
function add_subgraph(graph::OptiGraph; name::Symbol=Symbol(:sg, Symbol(UUIDs.uuid4())))
469469
subgraph = OptiGraph(; name=name)
470470
subgraph.parent_graph = graph
471471
push!(graph.subgraphs, subgraph)
472472
return subgraph
473473
end
474474

475475
"""
476-
add_subgraph(graph::OptiGraph; name::Symbol=Symbol(:sg,gensym()))
476+
add_subgraph(graph::OptiGraph; name::Symbol=Symbol(:sg, Symbol(UUIDs.uuid4())))
477477
478478
Add an existing subgraph to an optigraph. The subgraph cannot already be part of another
479479
optigraph. It also should not have nodes that already exist in the optigraph.

0 commit comments

Comments
 (0)