Skip to content

Commit 23e73ef

Browse files
committed
Add pytest for fetching example models and configs
1 parent 8380a34 commit 23e73ef

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

hls4ml/utils/example_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def fetch_example_model(model_name, backend='Vivado'):
156156

157157
if _config_is_available(model_name):
158158
config = _load_example_config(model_name)
159+
config[model_config] = model_name # Ensure that paths are correct
159160
else:
160161
config = _create_default_config(model_name, model_config, backend)
161162

test/pytest/test_fetch_example.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import ast
2+
import io
3+
from contextlib import redirect_stdout
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
import hls4ml
9+
10+
test_root_path = Path(__file__).parent
11+
12+
13+
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus'])
14+
def test_fetch_example_utils(backend):
15+
f = io.StringIO()
16+
with redirect_stdout(f):
17+
hls4ml.utils.fetch_example_list()
18+
out = f.getvalue()
19+
20+
model_list = ast.literal_eval(out) # Check if we indeed got a dictionary back
21+
22+
assert 'qkeras_mnist_cnn.json' in model_list['keras']
23+
24+
# This model has an example config that is also downloaded. Stored configurations don't set "Backend" value.
25+
config = hls4ml.utils.fetch_example_model('qkeras_mnist_cnn.json', backend=backend)
26+
config['KerasJson'] = 'qkeras_mnist_cnn.json'
27+
config['KerasH5']
28+
config['Backend'] = backend
29+
config['OutputDir'] = str(test_root_path / f'hls4mlprj_fetch_example_{backend}')
30+
31+
hls_model = hls4ml.converters.keras_to_hls(config)
32+
hls_model.compile() # For now, it is enough if it compiles, we're only testing downloading works as expected

0 commit comments

Comments
 (0)