src/HOL/Tools/ATP/system_on_tptp.scala
author wenzelm
Sun, 14 Mar 2021 15:28:44 +0100
changeset 73431 f27d7b12e8a4
parent 73430 c7f14309e291
child 73434 00b77365552e
permissions -rw-r--r--
support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73418
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     1
/*  Title:      HOL/Tools/ATP/system_on_tptp.scala
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     3
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     4
Support for remote ATPs via SystemOnTPTP.
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     5
*/
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     6
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     7
package isabelle.atp
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     8
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
     9
import isabelle._
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    10
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    11
import java.net.URL
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    12
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    13
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    14
object SystemOnTPTP
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    15
{
73420
wenzelm
parents: 73419
diff changeset
    16
  /* requests */
wenzelm
parents: 73419
diff changeset
    17
73418
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    18
  def get_url(options: Options): URL = Url(options.string("SystemOnTPTP"))
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    19
73422
fc7a0ea94c43 support timeout, similar to perl LWP::UserAgent;
wenzelm
parents: 73420
diff changeset
    20
  def post_request(
fc7a0ea94c43 support timeout, similar to perl LWP::UserAgent;
wenzelm
parents: 73420
diff changeset
    21
    url: URL,
fc7a0ea94c43 support timeout, similar to perl LWP::UserAgent;
wenzelm
parents: 73420
diff changeset
    22
    parameters: List[(String, Any)],
fc7a0ea94c43 support timeout, similar to perl LWP::UserAgent;
wenzelm
parents: 73420
diff changeset
    23
    timeout: Time = HTTP.Client.default_timeout): HTTP.Content =
73420
wenzelm
parents: 73419
diff changeset
    24
  {
wenzelm
parents: 73419
diff changeset
    25
    val parameters0 =
73431
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    26
      List("NoHTML" -> 1, "QuietFlag" -> "-q0")
73420
wenzelm
parents: 73419
diff changeset
    27
        .filterNot(p0 => parameters.exists(p => p0._1 == p._1))
73423
53cba4441cfb clarified error;
wenzelm
parents: 73422
diff changeset
    28
    try {
53cba4441cfb clarified error;
wenzelm
parents: 73422
diff changeset
    29
      HTTP.Client.post(url, parameters0 ::: parameters,
53cba4441cfb clarified error;
wenzelm
parents: 73422
diff changeset
    30
        timeout = timeout, user_agent = "Sledgehammer")
53cba4441cfb clarified error;
wenzelm
parents: 73422
diff changeset
    31
    }
53cba4441cfb clarified error;
wenzelm
parents: 73422
diff changeset
    32
    catch { case ERROR(msg) => cat_error("Failed to access SystemOnTPTP server", msg) }
73420
wenzelm
parents: 73419
diff changeset
    33
  }
wenzelm
parents: 73419
diff changeset
    34
wenzelm
parents: 73419
diff changeset
    35
wenzelm
parents: 73419
diff changeset
    36
  /* list systems */
wenzelm
parents: 73419
diff changeset
    37
73430
c7f14309e291 clarified signature;
wenzelm
parents: 73425
diff changeset
    38
  def list_systems(url: URL): HTTP.Content =
c7f14309e291 clarified signature;
wenzelm
parents: 73425
diff changeset
    39
    post_request(url, List("SubmitButton" -> "ListSystems", "ListStatus" -> "READY"))
73418
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    40
73419
22f3f2117ed7 clarified signature: function_thread is determined in Isabelle/Scala, not Isabelle/ML;
wenzelm
parents: 73418
diff changeset
    41
  object List_Systems extends Scala.Fun("SystemOnTPTP.list_systems", thread = true)
73418
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    42
  {
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    43
    val here = Scala_Project.here
73430
c7f14309e291 clarified signature;
wenzelm
parents: 73425
diff changeset
    44
    def apply(url: String): String = list_systems(Url(url)).string
73418
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    45
  }
73431
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    46
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    47
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    48
  /* run system */
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    49
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    50
  def run_system(url: URL,
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    51
    system: String,
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    52
    problem: String,
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    53
    extra: String = "",
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    54
    quiet: String = "01",
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    55
    timeout: Time = Time.seconds(60)): HTTP.Content =
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    56
  {
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    57
    val paramaters =
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    58
      List(
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    59
        "SubmitButton" -> "RunSelectedSystems",
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    60
        "ProblemSource" -> "FORMULAE",
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    61
        "FORMULAEProblem" -> problem,
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    62
        "ForceSystem" -> "-force",
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    63
        "System___" + system -> system,
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    64
        "TimeLimit___" + system -> timeout.seconds.ceil.toLong,
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    65
        "Command___" + system -> extra,
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    66
        "QuietFlag" -> ("-q" + quiet))
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    67
    post_request(url, paramaters, timeout = timeout + Time.seconds(15))
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    68
  }
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    69
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    70
  object Run_System extends Scala.Fun("SystemOnTPTP.run_system", thread = true)
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    71
  {
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    72
    val here = Scala_Project.here
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    73
    def apply(arg: String): String =
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    74
    {
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    75
      val List(url, system, problem, extra, Value.Int(timeout)) = Library.split_strings0(arg)
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    76
      val res = run_system(Url(url), system, problem, extra = extra, timeout = Time.ms(timeout))
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    77
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    78
      val bad_prover = "WARNING: " + system + " does not exist"
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    79
      if (res.trim_split_lines.exists(_.startsWith(bad_prover))) {
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    80
        error("The ATP " + quote(system) + " is not available at SystemOnTPTP")
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    81
      }
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    82
      else Library.cat_strings0(List(res.string, res.elapsed_time.ms.toString))
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    83
    }
f27d7b12e8a4 support for SystemOnTPTP.run_system, with strict error following scripts/remote_atp;
wenzelm
parents: 73430
diff changeset
    84
  }
73418
7d7d959547a1 support for SystemOnTPTP in Isabelle/ML and Isabelle/Scala (without perl);
wenzelm
parents:
diff changeset
    85
}