Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-38469: Remove read_quantum_graph method. #137

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/DM-38469.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove read_quantum_graph method as passing of butler repository's DimensionUniverse to QuantumGraph.loadUri() is no longer required.
3 changes: 1 addition & 2 deletions doc/changes/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ The ``<TYPE>`` should be one of:

An example file name would therefore look like ``DM-30291.misc.rst``.

You can test how the content will be integrated into the release notes by running ``towncrier --draft --version=V.vv``.
``towncrier`` can be installed from PyPI or conda-forge.
You can test how the content will be integrated into the release notes by running ``towncrier build --draft --version=V.vv`` in the package's top directory. ``towncrier`` can be installed from PyPI or conda-forge.
13 changes: 4 additions & 9 deletions python/lsst/ctrl/bps/clustered_quantum_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
from collections import Counter, defaultdict
from pathlib import Path

from lsst.pipe.base import NodeId
from lsst.pipe.base import NodeId, QuantumGraph
from lsst.utils.iteration import ensure_iterable
from networkx import DiGraph

from .bps_draw import draw_networkx_dot
from .pre_transform import read_quantum_graph

_LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -184,8 +183,6 @@
qgraph_filename : `str`
Filename for given QuantumGraph if it has already been
serialized.
butler_uri : `str`
Location of butler repo used to create the QuantumGraph.

Raises
------
Expand All @@ -199,20 +196,18 @@
use API over totally minimized memory usage.
"""

def __init__(self, name, qgraph, qgraph_filename=None, butler_uri=None):
def __init__(self, name, qgraph, qgraph_filename=None):
if "/" in name:
raise ValueError(f"name cannot have a / ({name})")
self._name = name
self._quantum_graph = qgraph
self._quantum_graph_filename = Path(qgraph_filename).resolve()
self._butler_uri = Path(butler_uri).resolve()
self._cluster_graph = DiGraph()

def __str__(self):
return (
f"ClusteredQuantumGraph(name={self.name},"
f"quantum_graph_filename={self._quantum_graph_filename},"
f"butler_uri ={self._butler_uri},"
f"len(qgraph)={len(self._quantum_graph) if self._quantum_graph else None},"
f"len(cqgraph)={len(self._cluster_graph) if self._cluster_graph else None})"
)
Expand Down Expand Up @@ -498,9 +493,9 @@

# The QuantumGraph was saved separately
try:
cgraph._quantum_graph = read_quantum_graph(cgraph._quantum_graph_filename, cgraph._butler_uri)
cgraph._quantum_graph = QuantumGraph.loadUri(cgraph._quantum_graph_filename)

Check warning on line 496 in python/lsst/ctrl/bps/clustered_quantum_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/bps/clustered_quantum_graph.py#L496

Added line #L496 was not covered by tests
except FileNotFoundError: # Try same path as ClusteredQuantumGraph
new_filename = path.parent / Path(cgraph._quantum_graph_filename).name
cgraph._quantum_graph = read_quantum_graph(new_filename, cgraph._butler_uri)
cgraph._quantum_graph = QuantumGraph.loadUri(new_filename)

Check warning on line 499 in python/lsst/ctrl/bps/clustered_quantum_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/bps/clustered_quantum_graph.py#L499

Added line #L499 was not covered by tests

return cgraph
33 changes: 1 addition & 32 deletions python/lsst/ctrl/bps/pre_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import subprocess

from lsst.ctrl.bps.bps_utils import _create_execution_butler
from lsst.daf.butler import Butler
from lsst.pipe.base.graph import QuantumGraph
from lsst.utils import doImport
from lsst.utils.logging import VERBOSE
Expand Down Expand Up @@ -106,7 +105,7 @@

_LOG.info("Reading quantum graph from '%s'", qgraph_filename)
with time_this(log=_LOG, level=logging.INFO, prefix=None, msg="Completed reading quantum graph"):
qgraph = read_quantum_graph(qgraph_filename, config["butlerConfig"])
qgraph = QuantumGraph.loadUri(qgraph_filename)

Check warning on line 108 in python/lsst/ctrl/bps/pre_transform.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/bps/pre_transform.py#L108

Added line #L108 was not covered by tests

if when_create.upper() == "QGRAPH_CMDLINE":
if not os.path.exists(execution_butler_dir):
Expand Down Expand Up @@ -191,36 +190,6 @@
return qgraph_filename


def read_quantum_graph(qgraph_filename, butler_uri):
"""Read the QuantumGraph from disk.

Parameters
----------
qgraph_filename : `str`
Name of file containing QuantumGraph to be used for workflow
generation.
butler_uri : `str`
Location of butler repository that can be used to create a
butler object.

Returns
-------
qgraph : `lsst.pipe.base.graph.QuantumGraph`
The QuantumGraph read from a file.

Raises
------
RuntimeError
If the QuantumGraph contains 0 Quanta.
"""
# Get the DimensionUniverse from the butler repository
butler = Butler(butler_uri, writeable=False)
qgraph = QuantumGraph.loadUri(qgraph_filename, butler.registry.dimensions)
if len(qgraph) == 0:
raise RuntimeError("QuantumGraph is empty")
return qgraph


def cluster_quanta(config, qgraph, name):
"""Call specified function to group quanta into clusters to be run
together.
Expand Down
2 changes: 0 additions & 2 deletions python/lsst/ctrl/bps/quantum_clustering_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def single_quantum_clustering(config, qgraph, name):
name=name,
qgraph=qgraph,
qgraph_filename=config[".bps_defined.runQgraphFile"],
butler_uri=config["butlerConfig"],
)

# Save mapping of quantum nodeNumber to name so don't have to create it
Expand Down Expand Up @@ -176,7 +175,6 @@ def dimension_clustering(config, qgraph, name):
name=name,
qgraph=qgraph,
qgraph_filename=config[".bps_defined.runQgraphFile"],
butler_uri=config["butlerConfig"],
)

# save mapping in order to create dependencies later
Expand Down