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

Patches with python task classes and attribute refactor #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions capnp/client.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using import "common.capnp".TaskId;
using import "common.capnp".GovernorId;
using import "common.capnp".DataObjectId;
using import "common.capnp".Attributes;
using import "common.capnp".SessionId;
using import "common.capnp".TaskState;
using import "common.capnp".DataObjectState;
Expand Down Expand Up @@ -67,7 +66,7 @@ interface ClientService {
terminateServer @8 () -> ();
# Quit server; the connection to the server will be closed after this call

fetch @9 (id :DataObjectId, includeMetadata :Bool, offset :UInt64, size :UInt64) -> FetchResult;
fetch @9 (id :DataObjectId, includeInfo :Bool, offset :UInt64, size :UInt64) -> FetchResult;
}

struct Update {
Expand All @@ -78,38 +77,23 @@ struct Update {
struct TaskUpdate {
id @0 :TaskId;
state @1 :TaskState;
attributes @2 :Attributes;
info @2 :Text;
}

struct DataObjectUpdate {
id @0 :DataObjectId;
state @1 :DataObjectState;
size @2 :UInt64;
attributes @3 :Attributes;
# Only valid when the state is `finished` and `removed`, otherwise should be 0.
info @2 :Text;
}
}

struct Task {
id @0 :TaskId;
inputs @1 :List(InDataObject);
outputs @2 :List(DataObjectId);
taskType @3 :Text;
attributes @4 :Attributes;

struct InDataObject {
id @0 :DataObjectId;
label @1 :Text;
path @2 :Text;
}
spec @0: Text;
}

struct DataObject {
id @0 :DataObjectId;
spec @0: Text;
keep @1 :Bool;
dataType @2 :DataType;
hasData @3: Bool;
data @4 :Data;
label @5 :Text;
attributes @6: Attributes;
hasData @2: Bool;
data @3 :Data;
}
18 changes: 3 additions & 15 deletions capnp/common.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ enum DataType {
directory @1;
}

struct Attributes {
items @0 :List(Item);

struct Item {
key @0 :Text;
value @1: Text;
}
}

struct Resources {
nCpus @0 :UInt32;
}
Expand Down Expand Up @@ -92,11 +83,6 @@ struct Timestamp {
subsecNanos @1 :UInt32;
}

struct FetchMetadata {
size @0 :Int64;
dataType @1 :DataType;
attributes @2 :Attributes;
}

struct FetchResult {

Expand Down Expand Up @@ -130,5 +116,7 @@ struct FetchResult {
}

data @6 :Data;
metadata @7: FetchMetadata;

# DataObject info
info @7: Text;
}
42 changes: 7 additions & 35 deletions capnp/governor.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ using import "common.capnp".GovernorId;
using import "common.capnp".TaskId;
using import "common.capnp".DataType;
using import "common.capnp".DataObjectId;
using import "common.capnp".Attributes;
using import "common.capnp".TaskState;
using import "common.capnp".DataObjectState;
using import "common.capnp".Resources;
Expand All @@ -19,7 +18,7 @@ interface GovernorBootstrap {
# Interface for entities connecting directly to the governor.
# Currently only governors would do this but in the future, other entities may do this.

fetch @0 (id :DataObjectId, includeMetadata :Bool, offset :UInt64, size :UInt64) -> FetchResult;
fetch @0 (id :DataObjectId, includeInfo :Bool, offset :UInt64, size :UInt64) -> FetchResult;
}

struct GovernorStateUpdate {
Expand All @@ -29,15 +28,13 @@ struct GovernorStateUpdate {
struct TaskUpdate {
id @0 :TaskId;
state @1 :TaskState;
attributes @2 :Attributes;
info @2 :Text;
}

struct DataObjectUpdate {
id @0 :DataObjectId;
state @1 :DataObjectState;
size @2 :UInt64;
attributes @3 :Attributes;
# Only valid when the state is `finished` and `removed`, otherwise should be 0.
info @2 :Text;
}
}

Expand Down Expand Up @@ -83,45 +80,20 @@ interface GovernorControl {
# Task instance

struct Task {
id @0 :TaskId;

inputs @1 :List(InDataObject);
outputs @2 :List(DataObjectId);

taskType @3 :Text;

attributes @4: Attributes;

# Number of request CPUs; will be replaced by more sophisticated
# resource requests

struct InDataObject {
id @0 :DataObjectId;
label @1 :Text;
path @2 :Text;
}
spec @0: Text;
}

# Data object instance information (not the data)

struct DataObject {
id @0 :DataObjectId;
spec @0: Text;

placement @1 :GovernorId;
# If equal to local governor id, then local, otherwise remote.

size @2 :Int64 = -1;
# In bytes, positive if known.

state @3 :DataObjectState;
state @2 :DataObjectState;
# Current object state. All input objects (external or local) should be `finished` or
# `running` (when streaming), output objects `assigned`.

assigned @4 :Bool;

label @5 :Text;

dataType @7 :DataType;

attributes @6 :Attributes;
assigned @3 :Bool;
}
5 changes: 5 additions & 0 deletions python/rain/client/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def __repr__(self):
return "<DObj {}{} id={} {}>".format(
self.label, t, self.id, self.attributes)

#def _as_outputclone(self):
# """
# Create a clone sharing the data_type and content_type (for use as an output).
# """


def blob(value, label="const", content_type=None, encode=None):
"""
Expand Down
12 changes: 11 additions & 1 deletion python/rain/client/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, label=None, *, size_hint=None, content_type=None,

self.path = path

def to_json(self):
def _to_json(self):
return {k: v for (k, v) in self.__dict__.items() if v is not None}

def _check_for_task(self, task, order):
Expand Down Expand Up @@ -95,6 +95,16 @@ def _for_program(cls, out, label=None, execute=False, label_as_path=False):

return out

def expect_dir(self):
"""Raise TypeError if the Output is not a directory data-type."""
if self.data_type != DataType.DIRECTORY:
raise TypeError("Directory output object expected.")

def expect_blob(self):
"""Raise TypeError if the Output is not a directory data-type."""
if self.data_type != DataType.BLOB:
raise TypeError("Directory output object expected.")


class Output(OutputBase):
data_type = DataType.BLOB
Expand Down
Loading