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

Make msgpack optional #1026

Closed
wants to merge 4 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## v0.2.0

- MsgPack support is now optional via the `msgpack` feature (enabled by default)

## v0.1.6

- Memory usage optimizations and reduced cloning
- Wellformed compiler pass to statically verify a computation with elk: elk compile -p wellformed comp.moose
- TLS support for gRCP networking
Expand Down
18 changes: 16 additions & 2 deletions moose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@ categories = ["", ""]
edition = "2018"

[features]
default = ["blas", "compile", "sync_execute", "async_execute"]
default = [
"blas",
"msgpack",
"compile",
"sync_execute",
"async_execute",
]
full = [
"blas",
"msgpack",
"compile",
"sync_execute",
"async_execute",
]
blas = ["ndarray-linalg"]
msgpack = ["rmp-serde"]
compile = []
sync_execute = []
async_execute = []
Expand Down Expand Up @@ -44,7 +58,7 @@ paste = "~1.0"
petgraph = "~0.6"
rand = { version = "~0.8", features = ["std", "std_rng"] }
rayon = "~1.5"
rmp-serde = "~1.0"
rmp-serde = { version = "~1.0", optional = true }
serde = { version="~1.0", features=["derive", "rc"] }
static_assertions = "~1.1"
thiserror = "~1.0"
Expand Down
12 changes: 9 additions & 3 deletions moose/src/computation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use petgraph::Graph;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
use std::fs::File;
use std::fs::OpenOptions;
use std::hash::{Hash, Hasher};
use std::io::prelude::*;
Expand Down Expand Up @@ -1807,11 +1806,13 @@ pub struct OperationIndex {
}

impl NamedComputation {
#[cfg(feature = "msgpack")]
#[tracing::instrument(skip(bytes))]
pub fn from_msgpack<B: AsRef<[u8]>>(bytes: B) -> Result<Self> {
rmp_serde::from_read_ref(&bytes).map_err(|e| Error::SerializationError(e.to_string()))
}

#[cfg(feature = "msgpack")]
#[tracing::instrument(skip(self))]
pub fn to_msgpack(&self) -> Result<Vec<u8>> {
rmp_serde::to_vec(self).map_err(|e| Error::SerializationError(e.to_string()))
Expand Down Expand Up @@ -1856,19 +1857,22 @@ impl NamedComputation {
bincode::serialize(self).map_err(|e| Error::SerializationError(e.to_string()))
}

#[cfg(feature = "msgpack")]
#[deprecated]
pub fn from_bytes(bytes: Vec<u8>) -> Result<Self> {
Self::from_msgpack(&bytes)
}

#[cfg(feature = "msgpack")]
#[deprecated]
pub fn to_bytes(&self) -> Result<Vec<u8>> {
self.to_msgpack()
}

#[cfg(feature = "msgpack")]
pub fn from_disk<P: AsRef<Path>>(path: P) -> Result<Self> {
let p = path.as_ref();
let f = File::open(p).map_err(|e| {
let f = std::fs::File::open(p).map_err(|e| {
Error::Unexpected(Some(format!(
"File not found error for path {0}. Original: {1}.",
p.display(),
Expand All @@ -1878,9 +1882,10 @@ impl NamedComputation {
rmp_serde::decode::from_read(f).map_err(|e| Error::SerializationError(e.to_string()))
}

#[cfg(feature = "msgpack")]
pub fn to_disk<P: AsRef<Path>>(&self, path: P) -> Result<()> {
let mut file_buffer =
File::create(path).map_err(|e| Error::SerializationError(e.to_string()))?;
std::fs::File::create(path).map_err(|e| Error::SerializationError(e.to_string()))?;
rmp_serde::encode::write(&mut file_buffer, self)
.map_err(|e| Error::SerializationError(e.to_string()))?;
Ok(())
Expand Down Expand Up @@ -1986,6 +1991,7 @@ mod tests {
assert_eq!(*session_id.as_bytes(), expected);
}

#[cfg(feature = "msgpack")]
#[test]
fn test_binary_roundtrip() {
use std::convert::TryInto;
Expand Down
6 changes: 3 additions & 3 deletions moose/src/host/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,9 @@ impl InverseOp {
_plc: &HostPlacement,
_x: HostTensor<T>,
) -> Result<HostTensor<T>> {
Err(Error::UnimplementedOperator(format!(
"Please enable 'blas' feature"
)))
Err(Error::UnimplementedOperator(
"Please enable 'blas' feature".to_string(),
))
}
}

Expand Down