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

Errors in Loading the “Template Writing” BuildingMOTIF Tutorial #212

Closed
wehuang16 opened this issue Jan 25, 2023 · 3 comments · Fixed by #227
Closed

Errors in Loading the “Template Writing” BuildingMOTIF Tutorial #212

wehuang16 opened this issue Jan 25, 2023 · 3 comments · Fixed by #227

Comments

@wehuang16
Copy link

wehuang16 commented Jan 25, 2023

Basically what I did was, with the “template writing” tutorial (https://nrel.github.io/BuildingMOTIF/tutorials/template_writing.html), I copied the following codes to a Jupyter notebook file named “template_writing_tutorial.ipynb”:

from rdflib import Namespace, Graph
from buildingmotif import BuildingMOTIF
from buildingmotif.dataclasses import Model, Library
lib = Library.load(directory="my-templates")
templ = lib.get_template_by_name("vav-terminal-reheat")

I also copied the following codes to a “.yaml” file named “vav-terminal-reheat.yaml”, where the file “vav-terminal-reheat.yaml” is inside a folder named “my-templates”:
Screen Shot 2023-01-25 at 2 51 38 PM

The setup of the aforementioned Jupyter Notebook file and the “my-templates” folder (containing the “.yaml” file) was shown here (https://drive.google.com/drive/folders/1mcN42q8JbkM-3Rwx2jNqdGPRvYg9GgUs?usp=share_link). The Jupyter Notebook file and the “my-templates” folder were stored in the “BuildingMOTIF/docs/tutorials” file path.

I first ran the “template_writing_tutorial.ipynb” file, but it returned the following error at the line
lib = Library.load(directory="my-templates") :
Screen Shot 2023-01-25 at 2 37 09 PM

Then I added the line bm = BuildingMOTIF("sqlite://"), so that the file “template_writing_tutorial.ipynb” now looks like the following:

from rdflib import Namespace, Graph
from buildingmotif import BuildingMOTIF
from buildingmotif.dataclasses import Model, Library
bm = BuildingMOTIF("sqlite://")
lib = Library.load(directory="my-templates")
templ = lib.get_template_by_name("vav-terminal-reheat")

I ran “template_writing_tutorial.ipynb” again. It returned the following error at the line
templ = lib.get_template_by_name("vav-terminal-reheat") :
Screen Shot 2023-01-25 at 3 03 50 PM

Therefore, I would like to raise this issue here to learn more about how we could resolve the above errors.

@haneslinger
Copy link
Collaborator

hello @wehuang16! Thank you for the ticket. I've got two small fixes that'll get this running.

Given the imports and building motif inti

from buildingmotif import BuildingMOTIF
from buildingmotif.dataclasses import Library

bm = BuildingMOTIF("sqlite://")

the lines

lib = Library.load(directory="./my-templates")
templ = lib.get_template_by_name("vav-terminal-reheat")

results in

WARNING: Warning: could not resolve dependency dep<name=https://brickschema.org/schema/Brick#Supply_Air_Flow_Sensor bindings={'name': 'sa-flow'} library=https://brickschema.org/schema/1.3/Brick id=None>
...
sqlalchemy.exc.NoResultFound: No row was found when one was required

This is because vav-terminal-reheat is dependent on the brick schema, which is not present. If we add it,

brick = Library.load(ontology_graph="./libraries/brick/Brick-subset.ttl")
lib = Library.load(directory="./my-templates")
templ = lib.get_template_by_name("vav-terminal-reheat")

We get the error

ValueError: In vav-terminal-reheat the values of the bindings to https://brickschema.org/schema/Brick#Occupancy_Sensor must correspond to the parameters in the dependant template.Dependency https://brickschema.org/schema/Brick#Occupancy_Sensor refers to params {'occ'} that do not appear in template vav-terminal-reheat

This is because vav-terminal-reheat details two dependencies it does not use, occ and co2. If we remove these two dependencies, or add them to vav-terminal-reheat's body the code will pass.

@wehuang16
Copy link
Author

Thank you so much for your information!

@gtfierro
Copy link
Collaborator

gtfierro commented Mar 1, 2023

It looks like this error arose because the sanity checking logic on templates does not take into account optional arguments. Actually, it is exactly because of the reason @haneslinger identified -- the parameters are not used in the body. I'll update this in the docs.

This should be a straightforward fix on my end. Sorry you ran into this!

@gtfierro gtfierro mentioned this issue Mar 1, 2023
@gtfierro gtfierro linked a pull request Mar 1, 2023 that will close this issue
gtfierro added a commit that referenced this issue Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants