<commit_before>#lang racket

(require "interact.rkt")
(require "../points.rkt")
(require "../alternative.rkt")
(require "../test.rkt")
(require "../config.rkt")

(define (run)
  (define in-expr (read))
  (eprintf "improving ~a...\n" in-expr)
  (define out-alt
    (match in-expr
      [`(herbie-test . ,_)
       (let ([tst (parse-test in-expr)])
         (set! in-expr (test-program tst))
         (run-improve (test-program tst) (*num-iterations*)
                      #:samplers (test-samplers tst)))]
      [`(,(or 'λ 'lambda) ,vars ,body)
       (run-improve in-expr (*num-iterations*))]
      [_ (error "did not recognize input")]))
  (printf "; Input error: ~a\n" (errors-score (alt-errors (make-alt in-expr))))
  (printf "; Output error: ~a\n" (errors-score (alt-errors out-alt)))
  (printf "~a\n" (alt-program out-alt)))

(module+ main
  (run))
<commit_msg>Add --seed, --fuel, and --num-points flags to inout.rkt<commit_after>#lang racket

(require "interact.rkt")
(require "../points.rkt")
(require "../alternative.rkt")
(require "../test.rkt")
(require "../config.rkt")

(define (run)
  (eprintf "; Seed: ~a\n" (pseudo-random-generator->vector (current-pseudo-random-generator)))
  (define in-expr (read))
  (define out-alt
    (match in-expr
      [`(herbie-test . ,_)
       (let ([tst (parse-test in-expr)])
         (set! in-expr (test-program tst))
         (run-improve (test-program tst) (*num-iterations*)
                      #:samplers (test-samplers tst)))]
      [`(,(or 'λ 'lambda) ,vars ,body)
       (run-improve in-expr (*num-iterations*))]
      [_ (error "did not recognize input")]))
  (printf "; Input error: ~a\n" (errors-score (alt-errors (make-alt in-expr))))
  (printf "; Output error: ~a\n" (errors-score (alt-errors out-alt)))
  (printf "~a\n" (alt-program out-alt)))

(module+ main
  (command-line
   #:program "herbie/inout.rkt"
   #:once-each
   [("-r" "--seed") rs "The random seed vector to use in point generation"
    (vector->pseudo-random-generator!
     (current-pseudo-random-generator)
     (read (open-input-string rs)))]
   [("--fuel") fu "The amount of 'fuel' to use"
    (*num-iterations* (string->number fu))]
   [("--num-points") points "The number of points to use"
    (*num-points* (string->number points))]
   #:multi
   [("-o" "--option") tf "Toggle flags, specified in the form category:flag"
    (let ([split-strings (string-split tf ":")])
      (when (not (= 2 (length split-strings)))
        (error "Badly formatted input " tf))
      (toggle-flag! (string->symbol (car split-strings)) (string->symbol (cadr split-strings))))]
   #:args _
   (run)))

{'fraction_non_alphanumeric': 0.20282658517952637, 'fraction_numerical': 0.0003819709702062643, 'mean_word_length': 2.9923780487804876, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2457224', 'n_tokens_mistral': 947, 'n_tokens_neox': 916, 'n_words': 236}