Skip to content

Commit

Permalink
Remove pyke and simplify testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo committed Jun 23, 2021
1 parent f49c600 commit 16959a5
Show file tree
Hide file tree
Showing 50 changed files with 862 additions and 3,301 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pip-cache
# Created by Iris build
*.so
lib/iris/etc/site.cfg
lib/iris/fileformats/_pyke_rules/compiled_krb/
lib/iris/std_names.py

# Iris test result files
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ include CHANGES COPYING COPYING.LESSER

# Files from setup.py package_data that are not automatically added to source distributions
recursive-include lib/iris/tests/results *.cml *.cdl *.txt *.xml *.json
recursive-exclude lib/iris/fileformats/_pyke_rules/compiled_krb *
recursive-include lib/iris/etc *
include lib/iris/fileformats/_pyke_rules/*.krb

recursive-include requirements *

Expand Down
1 change: 0 additions & 1 deletion asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"scipy": [],

"setuptools": [],
"pyke": [],
"six": [],

"nose": [],
Expand Down
2 changes: 1 addition & 1 deletion docs/src/developers_guide/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ To do this perform the following steps.
Create a conda environment with the appropriate conda packages to build the
source distribution (``sdist``) and pure Python wheel (``bdist_wheel``)::

> conda create -n iris-pypi -c conda-forge --yes pip pyke python setuptools twine wheel
> conda create -n iris-pypi -c conda-forge --yes pip python setuptools twine wheel
> . activate iris-pypi

Checkout the appropriate Iris ``<release>`` tag from the appropriate ``<repo>``.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The rest can be done with pip. Begin with numpy::
Finally, Iris and its Python dependencies can be installed with the following
command::

pip3 install setuptools cftime==1.2.1 cf-units scitools-pyke scitools-iris
pip3 install setuptools cftime==1.2.1 cf-units scitools-iris

This procedure was tested on a Ubuntu 20.04 system on the
27th of January, 2021.
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/fileformats/_nc_load_rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Interprets CF concepts identified by :mod:`iris.fileformats.cf` to add
components into loaded cubes.
For now : the API which mimics :class:`pyke.knowledge_engine.engine`.
For now : the API mimics :class:`pyke.knowledge_engine.engine`.
As this is aiming to replace the old Pyke-based logic rules.
TODO: simplify once the parallel operation with Pyke is no longer required.
Expand Down
4 changes: 0 additions & 4 deletions lib/iris/fileformats/_nc_load_rules/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
textual note that this rule 'failed', aka "did not trigger", which would not be
recorded in the original implementation.
The top-level 'run_actions' ensures that the individual rules actions are
called, with various arguments, as appropriate to ensure the whole cube is
built as it was by the original rules implementation.
TODO: remove the use of intermediate "facts" to carry information between
actions. This mimics older behaviour, so is still useful while we are still
comparing behaviour with the old Pyke rules (debugging). But once that is no
Expand Down
85 changes: 52 additions & 33 deletions lib/iris/fileformats/_nc_load_rules/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,47 @@
engine.get_kb() also returns a FactEntity object, which mimics *just enough*
API of a Pyke.knowlege_base, so that we can list its case-specific facts, as
used in :meth:`iris.fileformats.netcdf.pyke_stats`.
used in :meth:`iris.fileformats.netcdf._actions_activation_stats`.
"""
from .actions import run_actions


class FactList:
def __init__(self):
self.case_specific_facts = []


class FactEntity:
# To support:
"""
kb_facts = engine.get_kb(_PYKE_FACT_BASE)
An object with an 'entity_lists' property which is a dict of 'FactList's.
for key in kb_facts.entity_lists.keys():
for arg in kb_facts.entity_lists[key].case_specific_facts:
print("\t%s%s" % (key, arg))
A Factlist, in turn, is an object with property 'case_specific_facts',
which is a list of tuples of strings
(each of which is a 'fact' of the named class).
To support the debug code :
kb_facts = engine.get_kb(_PYKE_FACT_BASE)
for key in kb_facts.entity_lists.keys():
for arg in kb_facts.entity_lists[key].case_specific_facts:
print("\t%s%s" % (key, arg))
"""

def __init__(self):
self.entity_lists = {}

class _FactList:
# Just "an object with a 'case_specific_facts' property" (which is a list).
def __init__(self):
self.case_specific_facts = []

def add_fact(self, fact_name, args):
# Add a fact "fact_name(*args)".
if fact_name not in self.entity_lists:
self.entity_lists[fact_name] = FactList()
self.entity_lists[fact_name] = self._FactList()
fact_list = self.entity_lists[fact_name]
fact_list.case_specific_facts.append(tuple(args))

def sect_facts(self, entity_name):
if entity_name in self.entity_lists:
facts = self.entity_lists.get(entity_name).case_specific_facts
def sect_facts(self, fact_name):
# Lookup all facts "fact_name(*args)" for a given fact_name.
if fact_name in self.entity_lists:
facts = self.entity_lists.get(fact_name).case_specific_facts
else:
facts = []
return facts
Expand All @@ -61,6 +68,11 @@ class Engine:
Provides just enough API so that the existing code in
:mod:`iris.fileformats.netcdf` can interface with our new rules functions.
A list of possible fact-arglists is store, for each of a set of fact-names
(which are strings).
Each fact-argslist is represented by a tuple of values
-- at present, in practice, those are all strings too.
"""

def __init__(self):
Expand All @@ -71,50 +83,57 @@ def reset(self):
"""Reset the engine = remove all facts."""
self.facts = FactEntity()

def activate(self, rules_base_str=None):
def activate(self):
"""
Run all the translation rules to produce a single output cube.
This implicitly references the output variable for this operation,
set by engine.cf_var (the variable name).
The rules operation itself is coded elsewhere,
in :mod:`iris.fileformats.netcdf._nc_load_rules.rules`.
in :mod:`iris.fileformats.netcdf._nc_load_rules.actions`.
"""
run_actions(self)

def print_stats(self):
"""No-op, called by :meth:`iris.fileformats.netcdf.pyke_stats`."""
pass
def get_kb(self):
"""
Get a FactEntity, which mimic (bits of) a knowledge-base.
Just allowing
:meth:`iris.fileformats.netcdf._action_activation_stats` to list the
facts.
def add_case_specific_fact(self, kb_name, fact_name, fact_arglist):
"""
Record a fact about the current output operation.
return self.facts

Roughly, self.facts.entity_lists[fact_name].append(fact_arglist).
def print_stats(self):
"""
No-op, called by
:meth:`iris.fileformats.netcdf._action_activation_stats`.
"""
self.facts.add_fact(fact_name, fact_arglist)
pass

def get_kb(self, fact_base_str=None):
def add_case_specific_fact(self, fact_name, fact_arglist):
"""
Get a FactEntity, which mimic (bits of) a knowledge-base.
Record a fact about the current output operation.
Just allowing
:meth:`iris.fileformats.netcdf.pyke_stats` to list the facts.
Roughly,
facts = self.facts.entity_lists[fact_name].case_specific_facts
facts.append(fact_arglist)
"""
return self.facts
self.facts.add_fact(fact_name, fact_arglist)

def fact_list(self, fact_name):
"""
Return the facts (arg-lists) for one fact name.
A shorthand form used only by the new rules routines.
A shorthand form used only by the new 'actions' routines.
AKA 'case-specific-facts', in the original.
Roughly "return self.facts.entity_lists[fact_name]".
Roughly = "self.facts.entity_lists[fact_name].case_specific_facts".
"""
return self.facts.sect_facts(fact_name)
Expand All @@ -123,9 +142,9 @@ def add_fact(self, fact_name, fact_arglist):
"""
Add a new fact.
A shorthand form used only by the new rules routines.
A shorthand form used only by the new 'actions' routines.
"""
self.add_case_specific_fact(
kb_name="<n/a>", fact_name=fact_name, fact_arglist=fact_arglist
fact_name=fact_name, fact_arglist=fact_arglist
)
Loading

0 comments on commit 16959a5

Please sign in to comment.