Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Buckworth, Titus Frederick Christian C
arc
Commits
a60e1746
Commit
a60e1746
authored
3 months ago
by
tbuckworth
Browse files
Options
Downloads
Patches
Plain Diff
created Task class
parent
60d89fb9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
json_tests.py
+6
-23
6 additions, 23 deletions
json_tests.py
prolog/empty_solution.pl
+17
-0
17 additions, 0 deletions
prolog/empty_solution.pl
task.py
+5
-2
5 additions, 2 deletions
task.py
with
28 additions
and
25 deletions
json_tests.py
+
6
−
23
View file @
a60e1746
...
...
@@ -13,11 +13,8 @@ class TaskTester(unittest.TestCase):
cls
.
task_dict
=
load_task
()
#"data/training/0b148d64.json")
cls
.
task
=
Task
(
cls
.
task_dict
)
# Example of accessing input/output grids for the first example
cls
.
input_grid
=
cls
.
task_dict
[
'
train
'
][
0
][
'
input
'
]
cls
.
output_grid
=
cls
.
task_dict
[
'
train
'
][
0
][
'
output
'
]
cls
.
in_preds
=
grid2FOL
(
cls
.
input_grid
,
"
input
"
)
cls
.
out_preds
=
grid2FOL
(
cls
.
output_grid
,
"
output
"
)
cls
.
output_grid
=
cls
.
task
.
train_examples
[
0
].
output_grid
.
grid
cls
.
out_preds
=
cls
.
task
.
train_examples
[
0
].
output_grid
.
preds
def
test_ordering
(
self
):
out_preds
=
copy
.
deepcopy
(
self
.
out_preds
)
...
...
@@ -31,27 +28,13 @@ class TaskTester(unittest.TestCase):
out_grid
=
FOL2grid
(
out_FOL_array
)
self
.
assertTrue
((
out_grid
==
self
.
output_grid
).
all
())
def
test_prolog_program
(
self
):
in_prolog
=
FOL2prolog
(
self
.
in_preds
)
with
open
(
'
prolog/input_example_1.pl
'
,
'
w
'
)
as
file
:
file
.
write
(
in_prolog
)
program
=
"
[input_example_1], [solution_1], [background_knowledge], print_results, halt.
"
out_prolog
=
run_prolog_program
(
program
=
program
,
curr_dir
=
'
./prolog
'
)
out_FOL_array
=
prolog2FOL_array
(
out_prolog
)
out_grid
=
FOL2grid
(
out_FOL_array
)
array_and_plot_grid
(
self
.
output_grid
)
array_and_plot_grid
(
out_grid
)
self
.
assertTrue
((
out_grid
==
self
.
output_grid
).
all
())
def
test_task_class
(
self
):
solution
=
"
solution_1
"
res
=
self
.
task
.
try_solution
(
solution
)
self
.
assertTrue
(
res
)
print
(
res
)
def
test_task_empty
(
self
):
res
=
self
.
task
.
try_solution
(
"
empty_solution
"
)
self
.
assertFalse
(
res
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
prolog/empty_solution.pl
0 → 100644
+
17
−
0
View file @
a60e1746
all_rows
(
Rs
):-
setof
(
R
,
C
^
Colour
^
input_colour
(
R
,
C
,
Colour
),
Rs
).
all_cols
(
Cs
):-
setof
(
C
,
R
^
Colour
^
input_colour
(
R
,
C
,
Colour
),
Cs
).
row
(
R
):-
all_rows
(
Rs
),
member
(
R
,
Rs
).
column
(
C
):-
all_cols
(
Cs
),
member
(
C
,
Cs
).
output_colour
(
Row
,
Column
,
black
):-
row
(
Row
),
column
(
Column
).
This diff is collapsed.
Click to expand it.
task.py
+
5
−
2
View file @
a60e1746
import
numpy
as
np
from
main
import
colour_lookup
,
run_prolog_program
,
prolog2FOL_array
,
FOL2grid
,
grid2FOL
,
FOL2prolog
from
main
import
run_prolog_program
,
prolog2FOL_array
,
FOL2grid
,
grid2FOL
,
FOL2prolog
class
Grid
:
...
...
@@ -24,7 +24,10 @@ class Example:
out_FOL_array
=
prolog2FOL_array
(
out_prolog
)
out_grid
=
FOL2grid
(
out_FOL_array
)
result
=
(
out_grid
==
self
.
output_grid
.
grid
).
all
()
same
=
out_grid
==
self
.
output_grid
.
grid
result
=
same
.
all
()
if
not
result
:
print
(
f
"
output incorrect due to
{
(
~
same
).
sum
()
}
/
{
np
.
prod
(
same
.
shape
)
}
cells
"
)
return
result
class
Task
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment