Skip to content

Commit

Permalink
Merge pull request #73 from ModECI/experimental
Browse files Browse the repository at this point in the history
Fixes for macos-latest
  • Loading branch information
pgleeson authored Apr 25, 2024
2 parents ce5a73a + 73b5761 commit c928fb6
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 46 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
runs-on: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- runs-on: macos-14
- runs-on: macos-latest
python-version: "3.8"
- runs-on: macos-14
- runs-on: macos-latest
python-version: "3.9"

steps:
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
python contributors.py
cd sphinx
make clean
make html
make html
- name: Install and test with OMV
if: ${{ matrix.runs-on != 'windows-latest' }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,4 @@ cython_debug/
/examples/document.specification.bson
/examples/neuroml2/hello_world.v.dat
/examples/sbml/example_sbml_test.xml
/updatelibs.sh
1 change: 0 additions & 1 deletion docs/contributors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests
import pandas as pd
import json
import textwrap
from datetime import date

Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/source/api/Contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Modelspec contributors

This page list names and Github profiles of contributors to Modelspec, listed in no particular order.
This page is generated periodically, most recently on 2024-04-12.
This page is generated periodically, most recently on 2024-04-25.

- Padraig Gleeson ([@pgleeson](https://github.com/pgleeson))
- Manifest Chakalov ([@mqnifestkelvin](https://github.com/mqnifestkelvin))
Expand Down
1 change: 0 additions & 1 deletion examples/neuroml2/neuroml2_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class neuroml(Base):


if __name__ == "__main__":

nml_doc = neuroml(id="TestNeuroML")

izh = izhikevich2007Cell(
Expand Down
1 change: 0 additions & 1 deletion examples/sbml/sbml32spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class SBase(Base):

@modelspec.define
class SBaseWithId(SBase):

id: str = field(default=None, validator=optional([instance_of(str), valid_sid]))


Expand Down
3 changes: 1 addition & 2 deletions examples/sbml/sbml_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def valid_kind(instance, attribute, value):
if not value in sbml_si_units:
if value not in sbml_si_units:
raise ValueError(
f"kind {value} must be one of the standard SI units: {sbml_si_units}"
)
Expand Down Expand Up @@ -168,7 +168,6 @@ def validate_sbml(doc, units_consistency: bool = False) -> None:


if __name__ == "__main__":

import libsbml

sbml_file = sys.argv[1]
Expand Down
1 change: 0 additions & 1 deletion examples/sbml/test_sbml3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import json
import yaml
import os

from sbml32spec import *

Expand Down
10 changes: 0 additions & 10 deletions src/modelspec/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def from_dict(cls, d: Dict[str, Any]) -> "Base":
# If this object has an id attribute, it may have been serialized within a dict with the id as the key, even if
# it is a single object.
if "id" in [f.name for f in attr.fields(cls)] and "id" not in d.keys():

keys = list(d.keys())
if len(keys) == 0:
raise ValueError(
Expand All @@ -166,11 +165,6 @@ def from_yaml(cls, yaml_str: str) -> "Base":
"""Instantiate an modelspec object from a YAML string"""
return cls.from_dict(yaml.load(yaml_str, Loader=yaml.SafeLoader))

@classmethod
def from_yaml_file(cls, yaml_file: str) -> "Base":
"""Instantiate an modelspec object from a file containing YAML"""
return cls.from_dict(yaml.load(yaml_file, Loader=yaml.SafeLoader))

@classmethod
def from_json(cls, json_str: str) -> "Base":
"""Instantiate an modelspec object from a JSON string"""
Expand Down Expand Up @@ -297,7 +291,6 @@ def to_yaml_file(
filename = f"{self.id}.yaml"

with open(filename, "w") as outfile:

# We need to setup another
yaml.dump(
yaml_converter.unstructure(self.to_dict()),
Expand All @@ -313,7 +306,6 @@ def to_xml_file(
filename: Optional[str] = None,
include_metadata: bool = True,
) -> str:

if filename is None:
filename = f"{self.id}.xml"

Expand Down Expand Up @@ -636,7 +628,6 @@ def _is_base_type(
can_be_none=False,
can_be_eval_expr=False,
):

import numpy

if verbose:
Expand Down Expand Up @@ -730,7 +721,6 @@ def _cls_generate_documentation(cls, format: str = MARKDOWN_FORMAT):
rst_url_format = "`%s <%s>`__"

def insert_links(text, format=MARKDOWN_FORMAT):

code_ref = ":code:`"
# print(" > Converting: %s" % text)
text2 = text
Expand Down
45 changes: 20 additions & 25 deletions src/modelspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,12 @@ def convert_xml_dict_values(value):


def save_to_json_file(info_dict, filename, indent=4):

strj = json.dumps(info_dict, indent=indent)
with open(filename, "w") as fp:
fp.write(strj)


def save_to_yaml_file(info_dict, filename, indent=4):

if sys.version_info[0] == 2:
stry = yaml.dump(info_dict, indent=indent, default_flow_style=False)
else:
Expand Down Expand Up @@ -251,7 +249,6 @@ def build_xml_element(data, parent=None):

attrs = attr.fields(data.__class__)
for aattr in attrs:

print_(" == Looking at: {} ({})".format(aattr, type(aattr)), verbose)
if isinstance(aattr.default, attr.Factory):
children = data.__getattribute__(aattr.name)
Expand All @@ -272,15 +269,14 @@ def build_xml_element(data, parent=None):
)
if attribute_value is not None:
if (
type(attribute_value) is int
or type(attribute_value) is float
or type(attribute_value) is str
or type(attribute_value) is bool
or type(attribute_value) is list
isinstance(attribute_value, int)
or isinstance(attribute_value, float)
or isinstance(attribute_value, str)
or isinstance(attribute_value, bool)
or isinstance(attribute_value, list)
):
parent.set(attribute_name, str(attribute_value))
elif type(attribute_value) == dict:

elif isinstance(attribute_value, dict):
"""for k, v in attribute_value.items():
child_element = build_xml_element(v)"""
else:
Expand Down Expand Up @@ -309,7 +305,6 @@ def ascii_encode_dict(data):


def _parse_element(dict_format, to_build):

print_("Parse for element: [%s]" % dict_format, verbose)
for k in dict_format.keys():
print_(
Expand All @@ -323,7 +318,6 @@ def _parse_element(dict_format, to_build):


def _parse_attributes(dict_format, to_build):

for key in dict_format:
value = dict_format[key]
new_format = True
Expand All @@ -333,7 +327,7 @@ def _parse_attributes(dict_format, to_build):
)

if new_format:
if type(to_build) == dict:
if isinstance(to_build, dict):
to_build[key] = value

elif key in to_build.allowed_children:
Expand All @@ -345,11 +339,11 @@ def _parse_attributes(dict_format, to_build):
exec("to_build.%s.append(ff)" % key)
else:
if (
type(value) == str
or type(value) == int
or type(value) == float
or type(value) == bool
or type(value) == list
isinstance(value, str)
or isinstance(value, int)
or isinstance(value, float)
or isinstance(value, bool)
or isinstance(value, list)
or value is None
):
to_build.__setattr__(key, value)
Expand All @@ -370,11 +364,15 @@ def _parse_attributes(dict_format, to_build):
exec("to_build.%s = ff" % key)

else:
if type(to_build) == dict:
if isinstance(to_build, dict):
to_build[key] = value
elif type(value) == str or type(value) == int or type(value) == float:
elif (
isinstance(value, str)
or isinstance(value, int)
or isinstance(value, float)
):
to_build.__setattr__(key, value)
elif type(value) == list:
elif isinstance(value, list):
type_to_use = to_build.allowed_children[key][1]

for vl in value:
Expand Down Expand Up @@ -403,7 +401,7 @@ def locate_file(f, base_dir):


def _val_info(param_val):
if type(param_val) == np.ndarray:
if isinstance(param_val, np.ndarray):
pp = "%s" % (np.array2string(param_val, threshold=4, edgeitems=1))
pp = pp.replace("\n", "")
pp += f" (NP {param_val.shape} {param_val.dtype})"
Expand Down Expand Up @@ -489,7 +487,6 @@ def evaluate(
else:
expr = int(expr)
except:

try:
if array_format == FORMAT_TENSORFLOW:
expr = tf.constant(float(expr))
Expand Down Expand Up @@ -557,7 +554,6 @@ def evaluate(
)

if (type(v) is float or type(v) is str) and int(v) == v:

print_(" Returning int: %s" % int(v), verbose)

if array_format == FORMAT_TENSORFLOW:
Expand All @@ -576,7 +572,6 @@ def evaluate(


def parse_list_like(list_str):

if isinstance(list_str, int):
return [list_str]
elif isinstance(list_str, float):
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class TestUtils(unittest.TestCase):
def test_evaluate(self):

assert evaluate("33") == 33.0
assert evaluate("33") == 33
assert evaluate(33) == 33
Expand Down

0 comments on commit c928fb6

Please sign in to comment.