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

Reasoning with database #1836

Merged
merged 34 commits into from
Apr 8, 2018
Merged

Reasoning with database #1836

merged 34 commits into from
Apr 8, 2018

Conversation

eugenk
Copy link
Contributor

@eugenk eugenk commented Feb 26, 2018

This should add database support for reasoning. It changes the REST API wrt. Proving/Consistency-Checking.

Please review this carefully because there might be some typos when changing the state (moving through libEnv1, libEnv2, libEnv3 and so on while proving many conjectures). Please also check if there are any logical mistakes like not using the correct gTheory for proving/consistency-checking or not passing the set of all sentences (even imported ones) to the SInE premise selection.

REST API

  • POST /prove/coded-iri/command-list is for invoking a prover on a proof goal. It accepts the following request body
    {
      "format": "json", // or "xml" or "db" //optional
      "goals": [ // required
        {
          "node": "Nat__E1", // required
          "conjecture": "ga_comm___+__", // optional, if left out, every conjecture will be proved on its own with this configuration
          "reasonerConfiguration": { // required
            "timeLimit": 10, // seconds // required
            "reasoner": "EProver" // optional
          },
          "premiseSelection": { // optional
            "kind": "manual", // or "sine" // required
            "manualPremises": ["Ax1", "Ax2"], // required if kind is "manual"
            "sineDepthLimit": 5, // optional (default: unlimited)
            "sineTolerance": 1.7, // optional (default: 1.0)
            "sinePremiseNumberLimit": 50 // optional (default: unlimited)
          },
          "useTheorems": true, // use previously proven goals as axioms // optional (default: true)
          "printDetails": true, // print details of the proof in xml/json output // optional (default: true)
          "printProof": true // print the prover output in xml/json output // optional (default: true)
        }
      ]
    }
    
    Example call with curl:
    curl -X POST -H "Content-Type: application/json" -d '{"format": "db", "goals": [{"node": "Nat__E1", "conjecture": "ga_comm___+__", "reasonerConfiguration": {"timeLimit": 10, "reasoner": "EProver"}, "premiseSelection": {"kind": "sine", "sineDepthLimit": 2, "sineTolerance": 1, "sinePremiseNumberLimit": 50}}]}' "localhost:8000/consistency-check/$(urlencode $HETS_LIB/Basic/Numbers.casl)/auto/full-theories/full-signatures?hets-libdirs=$(urlencode $HETS_LIB)"
    
  • POST /consistency-check/coded-iri/command-list is for invoking a consistency-checker on a node. It accepts the following request body
    {
      "format": "json", // or "xml" or "db" //optional
      "goals": [ // required
        {
          "node": "Nat__E1", // required
          "reasonerConfiguration": { // required
            "timeLimit": 10, // seconds // required
            "reasoner": "darwin" // optional
          },
          "useTheorems": true, // use previously proven goals as axioms // optional (default: true)
        }
      ]
    }
    
    Example call with curl:
    curl -X POST -H "Content-Type: application/json" -d '{"format": "db", "goals": [{"node": "Nat__E1", "reasonerConfiguration": {"timeLimit": 10}}]}' "localhost:8000/prove/$(urlencode $HETS_LIB/Basic/Numbers.casl)/auto/full-theories/full-signatures?hets-libdirs=$(urlencode $HETS_LIB)"
    

To Do

@eugenk eugenk requested a review from tillmo February 26, 2018 09:44
@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

when compiling, I get a number of "missing module" warnings. I am just curious why missing modules do not cause errors. Have you employed some dynamic loading of modules at run-time?

WARNING in hptSomeThingsBelowUs
  missing module Persistence.Schema.ReasoningStatusOnConjectureType
  Probable cause: out-of-date interface files
WARNING in hptSomeThingsBelowUs
  missing module Persistence.Schema.ReasoningStatusOnReasoningAttemptType
  Probable cause: out-of-date interface files
WARNING in hptSomeThingsBelowUs
  missing module Persistence.Schema.ReasoningStatusOnConjectureType
  Probable cause: out-of-date interface files
WARNING in hptSomeThingsBelowUs
  missing module Persistence.Schema.ReasoningStatusOnReasoningAttemptType
  Probable cause: out-of-date interface files
[837 of 866] Compiling Driver.WriteFn   ( Driver/WriteFn.hs, Driver/WriteFn.o ) [Persistence.LogicGraph changed]
WARNING in hptSomeThingsBelowUs
  missing module Persistence.Schema.ReasoningStatusOnConjectureType
  Probable cause: out-of-date interface files
WARNING in hptSomeThingsBelowUs
  missing module Persistence.Schema.ReasoningStatusOnReasoningAttemptType
  Probable cause: out-of-date interface files
[839 of 866] Compiling Persistence.Reasoning ( Persistence/Reasoning.hs, Persistence/Reasoning.o )
[862 of 866] Compiling PGIP.Server      ( PGIP/Server.hs, PGIP/Server.o )
WARNING in hptSomeThingsBelowUs
  missing module Persistence.Schema.ReasoningStatusOnConjectureType
  Probable cause: out-of-date interface files
WARNING in hptSomeThingsBelowUs
  missing module Persistence.Schema.ReasoningStatusOnReasoningAttemptType
  Probable cause: out-of-date interface files

@eugenk
Copy link
Contributor Author

eugenk commented Feb 26, 2018

This is because of some left-overs that GHC hasn't detected. make clean should make that go away.

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

good, thanks. Now I have tried your example call and get:

curl -X POST -H "Content-Type: application/json" -d '{"format": "db", "goals": [{"node": "Nat__E1", "conjecture": "ga_comm___+__", "reasonerConfiguration": {"timeLimit": 10, "reasoner": "EProver"}, "premiseSelection": {"kind": "sine", "sineDepthLimit": 2, "sineTolerance": 1, "sinePremiseNumberLimit": 50}}]}' "localhost:8000/consistency-check/$(urlencode $HETS_LIB/Basic/Numbers.casl)/auto/full-theories/full-signatures?hets-libdirs=$(urlencode $HETS_LIB)"
*** Error:
user error (no cons checker found)

This is strange because 1) I have tried to prove, not to cons-check, 2) I have cons checkers available when using the old Hets GUI.

@eugenk
Copy link
Contributor Author

eugenk commented Feb 26, 2018

Is EProver a valid cons-checker?

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

no

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

OK, will try with "prove"

@eugenk
Copy link
Contributor Author

eugenk commented Feb 26, 2018

Then it is filtered away in

Hets/PGIP/Server.hs

Lines 1839 to 1847 in c7bf6ef

findConsChecker :: Maybe String -> G_sublogics -> Maybe String
-> IO (G_cons_checker, AnyComorphism)
findConsChecker translationM gSublogic consCheckerNameM = do
consList <- getFilteredConsCheckers translationM gSublogic
let findCC x = filter ((== x ) . getCcName . fst) consList
consCheckersL = maybe (findCC "darwin") findCC consCheckerNameM
case consCheckersL of
[] -> fail "no cons checker found"
(gConsChecker, comorphism) : _ -> return (gConsChecker, comorphism)

which is quite old Hets-code (just moved out into a separate function)

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

OK, I managed to prove a goal and found the prover output in table reasoner_outputs. I also managed to check consistency of an OMS. However, I did not find the output of the consistency checker in the DB.

Copy link
Contributor

@tillmo tillmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be offline soon, therefore just one comment for now.


data Action = Action { evaluationState :: String
, message :: Maybe String
} deriving (Show, Typeable, Data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this datatype called Action? It seems to be more a datatype for storing results of some action?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be extended to the action datatype that Tim described in his master's thesis. It can get an ETA and more information about the action in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good, then please add a corresponding comment.

@eugenk
Copy link
Contributor Author

eugenk commented Feb 26, 2018

I did not find the output of the consistency checker in the DB.

That's because Hets does not capture the output in the old function consNode.

Hets/PGIP/Server.hs

Lines 1821 to 1837 in c7bf6ef

consNode :: LibEnv -> LibName -> DGraph -> (Int, DGNodeLab)
-> G_sublogics -> Bool -> Maybe String -> Maybe String -> Maybe Int
-> ResultT IO (LibEnv, [ProofResult])
consNode le ln dg nl@(i, lb) subL useTh mp mt tl = do
(cc, c) <- liftIO $ findConsChecker mt subL mp
lift $ do
cstat <- consistencyCheck useTh cc c ln le dg nl $ fromMaybe 1 tl
-- Consistency Results are stored in LibEnv via DGChange object
let cSt = sType cstat
le'' = if cSt == CSUnchecked then le else
Map.insert ln (changeDGH dg $ SetNodeLab lb
(i, case cSt of
CSInconsistent -> markNodeInconsistent "" lb
CSConsistent -> markNodeConsistent "" lb
_ -> lb)) le
return (le'', [(" ", drop 2 $ show cSt, show cstat,
AbsState.ConsChecker cc, c, Nothing)])

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

OK, but could you then please create an issue for that?

PGIP/Server.hs Outdated
then case reasoningParametersE of
Left _ -> False
Right _ -> True
else True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorter:
not (validReasoningParams = elem newIde ["prove", "consistency-check"]) || Data.Either.isRight reasoningParametersE
or even
Data.Either.isRight reasoningParametersE <= (validReasoningParams = elem newIde ["prove", "consistency-check"])
Here, <= is read as "if", i.e. reverse "implies". See also https://mail.haskell.org/pipermail/libraries/2016-January/026565.html

PGIP/Server.hs Outdated

isLeft :: Either a b -> Bool
isLeft (Left _) = True
isLeft _ = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is already provided by Data.Either

PGIP/Server.hs Outdated

unRight :: Either a b -> b
unRight (Right x) = x
unRight _ = error "PGIP.Server.unRight received a Left."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorter: unRight = fromRight $ error "PGIP.Server.unRight received a Left."
Perhaps you could make the error message a bit more informative?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot use fromRight. It could not be found even though I have imported Data.Either.

@eugenk
Copy link
Contributor Author

eugenk commented Feb 26, 2018

OK, but could you then please create an issue for that?

I think I added it in 0555999.

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

yes, works, great!

PGIP/Server.hs Outdated
failOnLefts reasoningCache =
let lefts_ = filter isLeft reasoningCache
in if null lefts_
then return ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorter: if null $ lefts reasoningCache

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha, or better: let lefts_ = lefts reasoningCache

PGIP/Server.hs Outdated
reasonREST opts libEnv libName dGraph_ proverMode location reasoningParameters = do
reasoningCacheE <- liftIO $ buildReasoningCache
failOnLefts reasoningCacheE
let reasoningCache1 = map unRight $ filter (not . isLeft) reasoningCacheE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorter: let reasoningCache1 = rights reasoningCacheE
(you already know that there are only Right elements)

PGIP/Server.hs Outdated
)
[] $
groupBy (\ a b -> ReasoningParameters.node a == ReasoningParameters.node b) $
ReasoningParameters.goals reasoningParameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it hard to review buildReasoningCache. Could you please give names to the anonymous functions (even if this means passing more arguments around), and also to the groupby term at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. Could take me some time because I'm working on a different task right now.

Nothing ->
fail ("Cannot compute global theory of: "
++ showName (dgn_name nodeLabel) ++ "\n")
Just gTheory_ -> return gTheory_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a repetition of lines 1898ff. Could be relegated into a small function.

Nothing ->
fail ("Cannot compute global theory of: "
++ showName (dgn_name nodeLabel) ++ "\n")
Just gTheory_ -> return gTheory_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a repetition of lines 1898ff. Could be relegated into a small function.

@jelmd
Copy link
Contributor

jelmd commented Feb 26, 2018

BTW: In Issue ??? you asked for DB "driver" separation as done for MySQL. This would at least in theory allow a "no DB at all" configuration. So related questions are: Is that a supported config? If so, is the new code prepared for it (i.e. relevant parts enclosed in e.g. #ifdef USE_DB ... #endif )?

@eugenk
Copy link
Contributor Author

eugenk commented Feb 26, 2018

It is compatible to a no-db configuration.

@eugenk
Copy link
Contributor Author

eugenk commented Feb 26, 2018

The relevant code is only called if Hets has been called with database-related commandline-options.

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

I have a question about logic_translations. When I prove a simple first-order goal with a TPTP prover like SPASS, in the json I get

 "used_translation": "CASL2SoftFOL",

In the DB, I get

INSERT INTO "logic_translations" VALUES(1,'id-casl-condEq-casl2softfol');

How can a comorphism be reconstructed from id-casl-condEq-casl2softfol'? After all, this comorphism has two constituents, but the name uses three dashes.

EDIT: the problem should be even worse with

INSERT INTO "logic_translations" VALUES(2,'id-casl-condEq-casl2tptp-fof');

because id-casl-condEq-casl2tptp-fof cannot be split into its constituents by simple parsing.

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

The last question is relevant when I want to specify a translation (possibly a composition of logic mappings) that should be used for proving. Now my question is: how can I do this? I tried

till@mark:~/projects/Hets$ curl -X POST -H "Content-Type: application/json" -d '{"format": "db", "goals": [{"node": "sp", "conjecture": d=c", "reasonerConfiguration": {"timeLimit": 10, "reasoner": "SPASS"}, "translation": "casl2softfol", "premiseSelection": {"kind": "sine", "sineDepthLimit": 2, "sineTolerance": 1, "sinePremiseNumberLimit": 50}}]}' "localhost:8000/prove/$(urlencode /home/till/temp/prove.dol)/auto/full-theories/full-signatures?hets-libdirs=$(urlencode $HETS_LIB)"
*** Error:
user error (No matching translation or prover found for sp
)
till@mark:~/projects/Hets$ curl -X POST -H "Content-Type: application/json" -d '{"format": "db", "goals": [{"node": "sp", "conjecture": d=c", "reasonerConfiguration": {"timeLimit": 10, "reasoner": "SPASS"}, "translation": "CASL2SOFTFOL", "premiseSelection": {"kind": "sine", "sineDepthLimit": 2, "sineTolerance": 1, "sinePremiseNumberLimit": 50}}]}' "localhost:8000/prove/$(urlencode /home/till/temp/prove.dol)/auto/full-theories/full-signatures?hets-libdirs=$(urlencode $HETS_LIB)"
*** Error:
user error (No matching translation or prover found for sp
)

By the way, the error message would be more informative if the translation or prover that has not been found were included into the message.

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

It seems to be that only Persistence.LogicGraph.findLogicMappingBySlug can find a logic mapping, given a string. However, this function assumes that the logic mapping is already stored in the database. What if the user specifies a logic mapping (with several constituents) not present in the database, to be used for proving?

@tillmo
Copy link
Contributor

tillmo commented Feb 26, 2018

There seems to be problem with imported axioms. Consider

spec sp =
  sort s
  ops a,b,c:s
  . a=b %(a=b)%
  . b=c %(b=c)%
end

spec sp1 =
sp then
  . a=c %(a=c)% %implied
end

I get

curl -X POST -H "Content-Type: application/json" -d '{"format": "db", "goals": [{"node": "sp1", "conjecture": "a=c", "reasonerConfiguration": {"timeLimit": 10, "reasoner": "SPASS"}, "premiseSelection": {"kind": "sine", "sineDepthLimit": 2, "sineTolerance": 1, "sinePremiseNumberLimit": 50}}]}' "localhost:8000/prove/$(urlencode /home/till/temp/prove3.dol)/auto/full-theories/full-signatures?hets-libdirs=$(urlencode $HETS_LIB)"
*** Error:
Persistence.Reasoning.saveToDatabase: Could not find Sentence file:///home/till/temp/prove3.dol//oms/sp1/sentences/a=b 

although the sentence is there (but for OMS sp, not sp1!)

INSERT INTO "sentences" VALUES(41,36,12,'a=b','. a = b');
INSERT INTO "oms" VALUES(36,35,18,80,2,NULL,6,NULL,NULL,NULL,NULL,'dg_basic_spec',9,11,'sp','sp','',0,0,0,'Open');
INSERT INTO "oms" VALUES(43,35,19,80,2,NULL,7,NULL,NULL,NULL,NULL,'dg_basic_spec',10,14,'sp1','sp1','',0,0,0,'Open');
C

let goalName = fromJust $ rceGoalNameM reasoningCacheGoal
performPremiseSelection opts gTheory goalName
premiseSelectionParameters premiseSelectionKindV

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would omit this blank line, or else also add one before the returnbelow.

@tillmo
Copy link
Contributor

tillmo commented Apr 7, 2018

Note that the origin of sentences is now available, see #1837

@eugenk
Copy link
Contributor Author

eugenk commented Apr 7, 2018

I still would like to fix the origin in another pull request. I'm not sure if I should do something about travis not finishing for PostgreSQL. It will be difficult though, because recreating the cache and compiling consumes almost the whole time quota.

@tillmo
Copy link
Contributor

tillmo commented Apr 7, 2018

OK, then I suggest to merge this now.

@luisenriqueramos1977
Copy link

Hi, I am having the issue:
*** Error: no matching translation or prover found, when I try to prove an specification where an axiom is imported like the example commented by tillmo on 26 Feb 2018.
I wonder if there is a solution for such issue?.

Luis Ramos

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 this pull request may close these issues.

4 participants