Skip to content

Commit

Permalink
Remove spectral index and allow input of stokes varying by source, ti…
Browse files Browse the repository at this point in the history
…me and channel. (#244)
  • Loading branch information
sjperkins authored Apr 21, 2020
1 parent 8a2e742 commit e8b2e71
Show file tree
Hide file tree
Showing 64 changed files with 1,177 additions and 711 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ docs/make.bat
# Tensorflow build cruft
montblanc/tensorflow/rime_ops/.d/
montblanc/tensorflow/rime_ops/.swp
.kdev4
*.kdev4


__pycache__
14 changes: 7 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
master_doc = 'index'

# General information about the project.
project = u'montblanc'
copyright = u'2016, Simon Perkins'
author = u'Simon Perkins'
project = 'montblanc'
copyright = '2016, Simon Perkins'
author = 'Simon Perkins'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -231,8 +231,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'montblanc.tex', u'montblanc Documentation',
u'Simon Perkins', 'manual'),
(master_doc, 'montblanc.tex', 'montblanc Documentation',
'Simon Perkins', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -261,7 +261,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'montblanc', u'montblanc Documentation',
(master_doc, 'montblanc', 'montblanc Documentation',
[author], 1)
]

Expand All @@ -275,7 +275,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'montblanc', u'montblanc Documentation',
(master_doc, 'montblanc', 'montblanc Documentation',
author, 'montblanc', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
11 changes: 7 additions & 4 deletions install/cub.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@
import os
import shutil
import sys
import urllib2
try:
import urllib.request, urllib.error, urllib.parse
except ImportError:
import urllib2 as urllib
import zipfile

from install_log import log
from .install_log import log

class InstallCubException(Exception):
pass

def dl_cub(cub_url, cub_archive_name):
""" Download cub archive from cub_url and store it in cub_archive_name """
with open(cub_archive_name, 'wb') as f:
remote_file = urllib2.urlopen(cub_url)
remote_file = urllib.request.urlopen(cub_url)
meta = remote_file.info()

# The server may provide us with the size of the file.
Expand Down Expand Up @@ -158,4 +161,4 @@ def install_cub(mb_inc_path):
there, reason = is_cub_installed(cub_readme, cub_header, cub_version_str)

if not there:
raise InstallCubException(reason)
raise InstallCubException(reason)
4 changes: 2 additions & 2 deletions install/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import sys
import tempfile

from install_log import log
from .install_log import log

minimum_cuda_version = 8000

Expand Down Expand Up @@ -171,7 +171,7 @@ def inspect_cuda_version_and_devices(compiler, settings):
except Exception as e:
msg = ("Running the CUDA device check "
"stub failed\n{}".format(str(e)))
raise InspectCudaException(msg), None, sys.exc_info()[2]
raise InspectCudaException(msg)

return output

Expand Down
76 changes: 51 additions & 25 deletions install/tensorflow_ops_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import inspect
import itertools
import os

import six
from setuptools.extension import Extension
from setuptools.command.build_ext import build_ext

from install_log import log
from distutils import sysconfig
from .install_log import log

tensorflow_extension_name = 'montblanc.ext.rime'

Expand Down Expand Up @@ -151,36 +151,62 @@ def create_tensorflow_extension(nvcc_settings, device_info):
extra_link_args=extra_link_args,
)

def get_ext_filename_without_platform_suffix(filename):
name, ext = os.path.splitext(filename)
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')

if ext_suffix == ext:
return filename

ext_suffix = ext_suffix.replace(ext, '')
idx = name.find(ext_suffix)

if idx == -1:
return filename
else:
return name[:idx] + ext

class BuildCommand(build_ext):
""" Custom build command for building the tensorflow extension """

def get_ext_filename(self, ext_name):
if six.PY3:
filename = super().get_ext_filename(ext_name)
return get_ext_filename_without_platform_suffix(filename)
else:
return build_ext.get_ext_filename(self, ext_name)

def initialize_options(self):
build_ext.initialize_options(self)
self.nvcc_settings = None
self.cuda_devices = None

def finalize_options(self):
build_ext.finalize_options(self)

def run(self):
# Create the tensorflow extension during the run
# At this point, pip should have installed tensorflow
ext = create_tensorflow_extension(self.nvcc_settings,
self.cuda_devices)

for i, e in enumerate(self.extensions):
if not e.name == ext.name:
continue

# Copy extension attributes over to the dummy extension.
# Need to do this because the dummy extension has extra attributes
# created on it during finalize_options() that are required by run()
# and build_extensions(). However, tensorflow will not yet be installed
# at this point
for n, v in inspect.getmembers(ext):
setattr(e, n, v)

build_ext.run(self)
# def finalize_options(self):
# build_ext.finalize_options(self)

# def run(self):
# # Create the tensorflow extension during the run
# # At this point, pip should have installed tensorflow
# ext = create_tensorflow_extension(self.nvcc_settings,
# self.cuda_devices)

# for i, e in enumerate(self.extensions):
# if not e.name == ext.name:
# continue

# # Copy extension attributes over to the dummy extension.
# # Need to do this because the dummy extension has extra attributes
# # created on it during finalize_options() that are required by run()
# # and build_extensions(). However, tensorflow will not yet be installed
# # at this point

# for n, v in inspect.getmembers(ext):
# if n == "__weakref__":
# pass
# else:
# setattr(e, n, v)

# build_ext.run(self)

def build_extensions(self):
customize_compiler_for_nvcc(self.compiler,
Expand Down
4 changes: 2 additions & 2 deletions montblanc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# you try and set it
def constant(f):
def fset(self, value):
raise SyntaxError, 'Foolish Mortal! You would dare change a universal constant?'
raise SyntaxError('Foolish Mortal! You would dare change a universal constant?')
def fget(self):
return f()

Expand Down Expand Up @@ -62,7 +62,7 @@ def rime_solver_cfg(**kwargs):
-------
A SolverConfiguration object.
"""
from configuration import (load_config, config_validator,
from .configuration import (load_config, config_validator,
raise_validator_errors)

def _merge_copy(d1, d2):
Expand Down
22 changes: 11 additions & 11 deletions montblanc/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,20 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
if e.errno == errno.ENOENT:
continue
if verbose:
print("unable to run %s" % dispcmd)
print(("unable to run %s" % dispcmd))
print(e)
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
print(("unable to find command, tried %s" % (commands,)))
return None, None
stdout = p.communicate()[0].strip()
if sys.version_info[0] >= 3:
stdout = stdout.decode()
if p.returncode != 0:
if verbose:
print("unable to run %s (error)" % dispcmd)
print("stdout was %s" % stdout)
print(("unable to run %s (error)" % dispcmd))
print(("stdout was %s" % stdout))
return None, p.returncode
return stdout, p.returncode

Expand All @@ -124,8 +124,8 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
root = os.path.dirname(root) # up a level

if verbose:
print("Tried directories %s but none started with prefix %s" %
(str(rootdirs), parentdir_prefix))
print(("Tried directories %s but none started with prefix %s" %
(str(rootdirs), parentdir_prefix)))
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")


Expand Down Expand Up @@ -192,15 +192,15 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r'\d', r)])
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
print(("discarding '%s', no digits" % ",".join(refs - tags)))
if verbose:
print("likely tags: %s" % ",".join(sorted(tags)))
print(("likely tags: %s" % ",".join(sorted(tags))))
for ref in sorted(tags):
# sorting will prefer e.g. "2.0" over "2.0rc1"
if ref.startswith(tag_prefix):
r = ref[len(tag_prefix):]
if verbose:
print("picking %s" % r)
print(("picking %s" % r))
return {"version": r,
"full-revisionid": keywords["full"].strip(),
"dirty": False, "error": None,
Expand Down Expand Up @@ -229,7 +229,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
hide_stderr=True)
if rc != 0:
if verbose:
print("Directory %s not under git control" % root)
print(("Directory %s not under git control" % root))
raise NotThisMethod("'git rev-parse --git-dir' returned error")

# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
Expand Down Expand Up @@ -278,7 +278,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
if not full_tag.startswith(tag_prefix):
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
print((fmt % (full_tag, tag_prefix)))
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
% (full_tag, tag_prefix))
return pieces
Expand Down
10 changes: 5 additions & 5 deletions montblanc/examples/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def point_lm(self, context):
def point_stokes(self, context):
""" Supply point source stokes parameters to montblanc """

# Shape (npsrc, ntime, 4)
(ls, us), (lt, ut), (l, u) = context.array_extents(context.name)
# Shape (npsrc, ntime, nchan, 4)
(ls, us), (lt, ut), (lc, uc), (l, u) = context.array_extents(context.name)

data = np.empty(context.shape, context.dtype)
data[ls:us,:,l:u] = np.asarray(lm_stokes)[ls:us,None,:]
data[ls:us,:,:,l:u] = np.asarray(lm_stokes)[ls:us,None,None,:]
return data

def uvw(self, context):
Expand Down Expand Up @@ -96,7 +96,7 @@ def name(self):

def model_vis(self, context):
""" Receive model visibilities from Montblanc in `context.data` """
print context.data
print((context.data))

# Configure montblanc solver with a memory budget of 2GB
# and set it to double precision floating point accuracy
Expand All @@ -112,4 +112,4 @@ def model_vis(self, context):

# Call solver, supplying source and sink providers
slvr.solve(source_providers=source_provs,
sink_providers=sink_provs)
sink_providers=sink_provs)
Loading

0 comments on commit e8b2e71

Please sign in to comment.