Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/tiga1231/sgd2
08 April 2026, 17:08:34 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    No releases to show
  • 44ecc7e
  • /
  • example.py
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:ac8075ca51cca2540afdf94753ef94f0bb694697
origin badgedirectory badge
swh:1:dir:44ecc7e56a8fbd396aaebf600587fd102f7a1e57
origin badgerevision badge
swh:1:rev:13ca3d978626473e59fdddd641e457edc57208bc
origin badgesnapshot badge
swh:1:snp:139ff70469db38efd8ca16259dcc2fc37237cb74

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 13ca3d978626473e59fdddd641e457edc57208bc authored by jack on 02 March 2022, 18:24:49 UTC
update OS note
Tip revision: 13ca3d9
example.py
## custom
from utils import utils, vis
# from utils import poly_point_isect as bo   ##bentley-ottmann sweep line
import criteria as C
import quality as Q
# import gd2
from gd2 import GD2
import utils.weight_schedule as ws

## third party
import networkx as nx
# from PIL import Image
from natsort import natsorted

### numeric
import numpy as np
# import scipy.io as io
import torch
from torch import nn, optim
import torch.nn.functional as F

### vis
import tqdm
import matplotlib.pyplot as plt
# import matplotlib.animation as animation
# from matplotlib.colors import LinearSegmentedColormap
# from mpl_toolkits import mplot3d
# from matplotlib import collections  as mc
# from mpl_toolkits.mplot3d.art3d import Line3DCollection
plt.style.use('ggplot')
plt.style.use('seaborn-colorblind')


## sys
from collections import defaultdict
import random
import time
from glob import glob
import math
import os
from pathlib import Path
import itertools
import pickle as pkl



    



device = 'cpu'

seed = 2337
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)

# graph_name = 'grid_6_10'
# G = nx.grid_2d_graph(6,10)
# max_iter = int(1e4)

graph_name = 'dwt_307'
max_iter = int(1e4)
mat_dir = 'input_graphs/SuiteSparse Matrix Collection'
G = utils.load_mat(f'{mat_dir}/{graph_name}.mat')

 
criteria = ['stress', 'ideal_edge_length', 'aspect_ratio']
criteria_weights = dict(
    stress=ws.SmoothSteps([max_iter/4, max_iter], [1, 0.05]),
    ideal_edge_length=ws.SmoothSteps([0, max_iter*0.2, max_iter*0.6, max_iter], [0, 0, 0.2, 0]),
    aspect_ratio=ws.SmoothSteps([0, max_iter*0.2, max_iter*0.6, max_iter], [0, 0, 0.5, 0]),
)
criteria = list(criteria_weights.keys())

# plot_weight(criteria_weights, max_iter)
# plt.close()


sample_sizes = dict(
    stress=16,
    ideal_edge_length=16,
    neighborhood_preservation=16,
    crossings=128,
    crossing_angle_maximization=64,
    aspect_ratio=max(128, int(len(G)**0.5)),
    angular_resolution=16,
    vertex_resolution=max(256, int(len(G)**0.5)),
    gabriel=64,
)
sample_sizes = {c:sample_sizes[c] for c in criteria}




gd = GD2(G)
result = gd.optimize(
    criteria_weights=criteria_weights, 
    sample_sizes=sample_sizes,
    
    # evaluate='all',
    evaluate=set(criteria),
    
    max_iter=max_iter,
    time_limit=3600, ##sec
    
    evaluate_interval=max_iter, evaluate_interval_unit='iter',
    vis_interval=-1, vis_interval_unit='sec',
    
    clear_output=True,
    grad_clamp=20,
    criteria_kwargs = dict(
        aspect_ratio=dict(target=[1,1]),
    ),
#     optimizer_kwargs = dict(mode='Adam', lr=0.01),
    optimizer_kwargs = dict(mode='SGD', lr=2),
    scheduler_kwargs = dict(verbose=True),
)





## output 
pos = gd.pos.detach().numpy().tolist()
pos_G = {k:pos[gd.k2i[k]] for k in gd.G.nodes}

print('nodes')
for node_id, pos in pos_G.items():
    print(f'{node_id}, {pos[0]}, {pos[1]}')

print('edges')
for e in gd.G.edges:
    print(f'{e[0]}, {e[1]}')

## vis
vis.plot(
    gd.G, pos_G,
    [gd.iters, gd.loss_curve], 
    result['iter'], result['runtime'],
    criteria_weights, max_iter,
    # show=True, save=False,
    node_size=1,
    edge_width=1,
)
plt.show()

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API