Skip to content

Commit

Permalink
Merge pull request #109 from nlesc-dirac/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
HannoSpreeuw authored Sep 4, 2019
2 parents 4737d6e + aa34c69 commit 7b3c9e4
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/MPI/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ print_help(void) {
/* command line parsing for both master/slaves */
void
ParseCmdLine(int ac, char **av) {
char c;
int c;
while((c=getopt(ac, av, "c:e:f:g:j:k:l:m:n:o:p:q:r:s:t:x:y:A:B:C:E:F:I:J:K:L:O:P:Q:G:H:R:S:T:W:E:MVh"))!= -1)
{
switch(c)
Expand Down
4 changes: 2 additions & 2 deletions src/MS/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int Data::TileSize = 120;
int Data::Nt= 6;
char *Data::SkyModel=NULL;
char *Data::Clusters=NULL;
int Data::format=0; /* old LSM */
int Data::format=1; /* defaut is LSM with 3rd order spectra */
double Data::nulow=2.0;
double Data::nuhigh=30.0;

Expand All @@ -63,7 +63,7 @@ int Data::DoDiag=0;
int Data::doChan=0; /* if 1, solve for each channel in multi channel data */
int Data::doBeam=0; /* if >0, enable LOFAR beam model */
int Data::phaseOnly=0; /* if >0, enable phase only correction */
int Data::solver_mode=0;
int Data::solver_mode=SM_RTR_OSRLM_RLBFGS; /* use RTR+LBFGS by default */
int Data::ccid=-99999;
double Data::rho=1e-9;
char *Data::solfile=NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/MS/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ print_help(void) {
void
ParseCmdLine(int ac, char **av) {
print_copyright();
char c;
int c;
if(ac < 2)
{
print_help();
Expand Down
26 changes: 20 additions & 6 deletions src/buildsky/create_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,18 @@ def radec_to_lm_SIN(ra0,dec0,ra,dec):


#### main clustering routine : Q clusters
def cluster_this(skymodel,Q,outfile,max_iterations):
def cluster_this(skymodel,Q,outfile,max_iterations=5):
SKY=read_lsm_sky(skymodel)
K=len(SKY)

# negative_cluster_ids will keep a record of the user's request for negative cluster ids,
# The user can indicate this by entering a negative number of clusters.
if Q<0:
negative_cluster_ids=True
Q=-Q
else:
negative_cluster_ids=False

# check if we have more sources than clusters, otherwise change Q
if Q>K:
Q=K
Expand All @@ -234,7 +243,7 @@ def cluster_this(skymodel,Q,outfile,max_iterations):
C[ci,0]=X[sImax,0]
C[ci,1]=X[sImax,1]
sItmp[sImax]=0.0
#print C
#print(C)
# calculate weights

# arrays to store which cluster each source belongs to
Expand All @@ -255,15 +264,15 @@ def cluster_this(skymodel,Q,outfile,max_iterations):
mra=X[ci,0]
mdec=X[ci,1]
closest=find_closest(mra,mdec,C,Ccos,Csin)
#print "src %d closest %d"%(ci,closest)
#print("src %d closest %d"%(ci,closest))
CL[ci]=closest
# add this source to dict
if closest in D:
D[closest].append(ci)
else:
D[closest]=list()
D[closest].append(ci)
#print D
#print(D)

# check to see also if source assignment changes
if numpy.sum(CL-CLold)==0:
Expand Down Expand Up @@ -312,7 +321,10 @@ def cluster_this(skymodel,Q,outfile,max_iterations):
outF=open(outfile,'w+')
outF.write('# Cluster file\n')
for (clusid,sourcelist) in list(D.items()):
outF.write(str(clusid+1)+' 1')
if negative_cluster_ids==False:
outF.write(str(clusid+1)+' 1')
else:
outF.write(str(-clusid-1)+' 1')
for sourceid in sourcelist:
outF.write(' '+sources[sourceid])
outF.write('\n')
Expand All @@ -322,13 +334,15 @@ def cluster_this(skymodel,Q,outfile,max_iterations):
import sys
parser=optparse.OptionParser()
parser.add_option('-s', '--skymodel', help='Input sky model')
parser.add_option('-c', '--clusters', type='int', help='Number of clusters')
parser.add_option('-c', '--clusters', type='int', help='Number of clusters. Absolute value if negative and the cluster ids will be negative.')
parser.add_option('-o', '--outfile', help='Output cluster file')
parser.add_option('-i', '--iterations', type='int', help='Number of iterations')
(opts,args)=parser.parse_args()

if opts.skymodel and opts.clusters and opts.outfile and opts.iterations:
cluster_this(opts.skymodel,opts.clusters,opts.outfile,opts.iterations)
elif opts.skymodel and opts.clusters and opts.outfile:
cluster_this(opts.skymodel,opts.clusters,opts.outfile)
else:
parser.print_help()
exit()
4 changes: 3 additions & 1 deletion src/lib/Dirac/lbfgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,9 @@ lbfgs_fit_minibatch(
}*/
parallel_outer_product(m,indata->running_avg_sq,g_min_rold,g_min_rnew,indata->Nt);

/* estimate online variance */
/* estimate online variance
Note: for badly initialized cases, might need to increase initial value of alphabar
because of gradnrm is too large, alphabar becomes too small */
alphabar=10.0/(1.0+my_dasum(m,indata->running_avg_sq)/((double)(indata->niter-1)*gradnrm));
#ifdef DEBUG
printf("iter=%d running_avg %lf gradnrm %lf alpha=%lf\n",indata->niter,my_dasum(m,indata->running_avg_sq),gradnrm,alphabar);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Dirac/lmfit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ bfgsfit_visibilities(double *u, double *v, double *w, double *x, int N,
lmdata.Nt=64; /* increase threads for MIC */
#endif
/* use LBFGS */
if (solver_mode==2 || solver_mode==3) {
if (solver_mode==SM_RLM_RLBFGS || solver_mode==SM_OSLM_OSRLM_RLBFGS || solver_mode==SM_RTR_OSRLM_RLBFGS || solver_mode==SM_NSD_RLBFGS ) {
lmdata.robust_nu=mean_nu;
lbfgs_fit_robust_wrapper(p, x, m, n, max_lbfgs, lbfgs_m, gpu_threads, (void*)&lmdata);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Dirac/lmfit_cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ bfgsfit_visibilities_gpu(double *u, double *v, double *w, double *x, int N,

if (max_lbfgs>0) {
/* use LBFGS */
if (solver_mode==2 || solver_mode==3) {
if (solver_mode==SM_RLM_RLBFGS || solver_mode==SM_OSLM_OSRLM_RLBFGS || solver_mode==SM_RTR_OSRLM_RLBFGS || solver_mode==SM_NSD_RLBFGS) {
lmdata.robust_nu=mean_nu;
lbfgs_fit_robust_cuda(p, x, m, n, max_lbfgs, lbfgs_m, gpu_threads, (void*)&lmdata);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/lib/Dirac/load_balance.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ destroy_task_hist(taskhist *th) {
in such a way to allow load balancing */
int
select_work_gpu(int max_gpu, taskhist *th) {
if (!max_gpu) return 0; /* no need to spend time if only one GPU is available */
#ifdef MPI_BUILD
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
Expand Down
Loading

0 comments on commit 7b3c9e4

Please sign in to comment.