Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Richert committed Apr 28, 2020
2 parents f7917ec + fbb1d26 commit cea526d
Show file tree
Hide file tree
Showing 27 changed files with 413 additions and 597 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.9.1-dev0
current_version = 0.9.1-dev2
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: python
python:
- "3.6"
- "3.7"

# install dependencies
install:
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog

## 0.9.0
## 0.9

### 0.9.1 (work in progress)

- updated documentation
- removed conversion function register, because the functions were not used and made the code unnecessarily complicated
- might be replaced by a graph-based conversion path-finder in the future, if necessary
- Extended support for loading circuits from and saving to files
- supported formats: `yaml`, `pickle`
- supported classes: templates

### 0.9.0

- Added experimental support for multiple source variables per edge
- edges can either have multiple input variable from the same input node, or
Expand Down
2 changes: 1 addition & 1 deletion pyrates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

__author__ = "Richard Gast, Daniel Rose"
__status__ = "Development"
__version__ = "0.9.1-dev0"
__version__ = "0.9.1-dev2"


class PyRatesException(Exception):
Expand Down
19 changes: 1 addition & 18 deletions pyrates/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,11 @@

# template-based interface
from pyrates.frontend import template
# from pyrates.frontend import dict as dict_
from pyrates.frontend import yaml
# from pyrates.frontend import nxgraph
from pyrates.frontend.fileio import yaml
from pyrates.frontend.template import CircuitTemplate, NodeTemplate, EdgeTemplate, OperatorTemplate

# By importing the above, all transformation functions (starting with `to_` or `from_`) are registered
# Below these functions are collected and made available from pyrates.frontend following the naming convention
# `{target}_from_{source}` with target and source being respective valid representations in the frontend

from pyrates.frontend._registry import REGISTERED_INTERFACES
import sys

# add all registered functions to main frontend module
this_module = sys.modules[__name__]

for new_name, func in REGISTERED_INTERFACES.items():
# set new name on current module
setattr(this_module, new_name, func)


# The following function are shorthands that bridge multiple interface steps

def circuit_from_yaml(path: str):
"""Directly return CircuitIR instance from a yaml file."""
return CircuitTemplate.from_yaml(path).apply()
Expand Down
72 changes: 0 additions & 72 deletions pyrates/frontend/_registry.py

This file was deleted.

8 changes: 4 additions & 4 deletions pyrates/frontend/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
from pyrates.ir.edge import EdgeIR
from pyrates.ir.operator import OperatorIR

from pyrates.frontend._registry import register_interface


__author__ = "Daniel Rose"
__status__ = "Development"


# @register_interface
#
# def to_node(node_dict: dict):
#
# order = node_dict["operator_order"]
Expand Down Expand Up @@ -70,15 +70,15 @@
# return NodeIR(operators=operators)
#
#
# @register_interface
#
# def to_operator(op_dict: dict):
# from pyrates.frontend import OperatorTemplate
# template = OperatorTemplate(**op_dict)
#
# return template.apply()
#

@register_interface

def from_circuit(circuit: CircuitIR):
"""Reformat graph structure into a dictionary that can be saved as YAML template. The current implementation assumes
that nodes and edges are given by as templates."""
Expand Down
5 changes: 3 additions & 2 deletions pyrates/frontend/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import importlib

from pyrates import PyRatesException
from pyrates.frontend import yaml as _yaml
from pyrates.frontend.fileio import yaml as _yaml

__author__ = "Daniel Rose"
__status__ = "Development"
Expand All @@ -53,7 +53,8 @@


def parse_path(path: str):
"""Parse a path of form path.to.template, returning a tuple of (name, file, abspath)."""
"""Parse a path of form path.to.template_file.template_name or path/to/template_file/template_name,
returning a tuple of (name, file, abspath)."""

if "/" in path or "\\" in path:
import os
Expand Down
Empty file.
19 changes: 19 additions & 0 deletions pyrates/frontend/fileio/pickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Interface to load from and save to python pickles."""


def dump(data, filename):
import pickle

from pyrates.utility.filestorage import create_directory
create_directory(filename)

pickle.dump(data, open(filename, 'wb'), protocol=pickle.HIGHEST_PROTOCOL)



def load(filename):
import pickle

data = pickle.load(open(filename, 'rb'))

return data
23 changes: 10 additions & 13 deletions pyrates/frontend/yaml.py → pyrates/frontend/fileio/yaml.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@
# Richard Gast and Daniel Rose et. al. in preparation
""" Some utility functions for parsing YAML-based definitions of circuits and components.
"""
from pyrates.frontend._registry import register_interface


__author__ = "Daniel Rose"
__status__ = "Development"


@register_interface
def to_dict(path: str):
"""Load a template from YAML and return the resulting dictionary.
Parameters
----------
path
string containing path of YAML template of the form path.to.template or path/to/template.file.TemplateName.
The dot notation refers to a path that can be found using python's import functionality. The slash notation
refers to a file in an absolute or relative path from the current working directory.
(str) path to YAML template of the form `path.to.template_file.template_name` or
path/to/template_file/template_name.TemplateName. The dot notation refers to a path that can be found
using python's import functionality. That means it needs to be a module (a folder containing an `__init__.py`)
located in the Python path (e.g. the current working directory). The slash notation refers to a file in an
absolute or relative path from the current working directory. In either case the second-to-last part refers to
the filename without file extension and the last part refers to the template name.
"""
from pyrates.frontend.file import parse_path

Expand Down Expand Up @@ -81,10 +83,10 @@ def to_dict(path: str):
return template_dict


@register_interface
def from_circuit(circuit, path: str, name: str):
from pyrates.frontend.dict import from_circuit
dict_repr = {name: from_circuit(circuit)}
"""Interface to dump a CircuitIR instance to YAML."""
from pyrates.frontend.dict import from_circuit as dict_from_circuit
dict_repr = {name: dict_from_circuit(circuit)}

from ruamel.yaml import YAML
yaml = YAML()
Expand All @@ -94,8 +96,3 @@ def from_circuit(circuit, path: str, name: str):
from pathlib import Path
path = Path(path)
yaml.dump(dict_repr, path)


@register_interface
def to_template(path: str, template_cls):
return template_cls.from_yaml(path)

0 comments on commit cea526d

Please sign in to comment.