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

Change placeholders to {test} and {seq}, stop enforcing .itf.json extension, rename test --output to test --out-itf #1485

Merged
merged 16 commits into from
Aug 29, 2024

Conversation

romac
Copy link
Member

@romac romac commented Aug 21, 2024

Closes: #1484
Closes: #1137

run, test

  • Change placeholders from {} to {test} and from {#} to {seq}

run

  • Auto-append trace sequence number to filename if more than one trace is present and {seq} is not specified

test

  • Stop enforcing .itf.json extension
  • Rename --output to --out-itf, add hidden alias for the former
  • Show output (ie. test results) even if --out-itf is set

verify

  • Add warning if --out-itf option contains {test} or {seq} as those have no effect since Apalache only produces a single trace

@romac romac requested a review from bugarela August 21, 2024 06:40
Copy link
Collaborator

@bugarela bugarela left a comment

Choose a reason for hiding this comment

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

Hi, thanks for taking care of this! I see that a couple of integration tests are breaking because the expected files were not created on quint run with --n-traces. Just flagging this if you want to take a look - otherwise I'll debug this later in the week

@romac
Copy link
Member Author

romac commented Aug 21, 2024

Sure, I'll take a look :)

@romac romac requested a review from bugarela August 21, 2024 12:07
@konnov
Copy link
Contributor

konnov commented Aug 22, 2024

Just a note on {#}. I guess, it is my fault introducing it. The issue is that GNU parallel is using the same substitution syntax for the job number. If you plan to use Quint with parallel, this is going to be a problem.

@bugarela
Copy link
Collaborator

Just a note on {#}. I guess, it is my fault introducing it. The issue is that GNU parallel is using the same substitution syntax for the job number. If you plan to use Quint with parallel, this is going to be a problem.

Hmm interesting. I think it's a good idea to use the same standard as other program. I guess you can always wrap your quint command in a shell script or something and then call parallel on that to avoid the issue?

Copy link
Collaborator

@bugarela bugarela left a comment

Choose a reason for hiding this comment

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

LGTM ✨

@romac
Copy link
Member Author

romac commented Aug 22, 2024

Ah good point @konnov, I did not think of that.

I guess the solution @bugarela works, but it's also possible to change the parallel replacement string to something else using its --seqreplace option: https://www.gnu.org/software/parallel/parallel_tutorial.html

@konnov What do you think, are those workarounds good enough for you?

@konnov
Copy link
Contributor

konnov commented Aug 22, 2024

Ah good point @konnov, I did not think of that.

I guess the solution @bugarela works, but it's also possible to change the parallel replacement string to something else using its --seqreplace option: https://www.gnu.org/software/parallel/parallel_tutorial.html

@konnov What do you think, are those workarounds good enough for you?

Well, it would kind of work, but parallel is tough enough alone, so adding complexity on top of it would make things even harder :)

@romac
Copy link
Member Author

romac commented Aug 22, 2024

I agree it's a bit more complex, but you only have to figure out the right invocation of parallel once, then you can re-use it everywhere. On the other hand, changing the variable would involve making a breaking change in the Quint CLI, since we also use {#} and {} in other commands as well (i.e. quint test --output).

That said, I empathize with the goal of building tools (Quint in this case) which work well with other pre-existing tools, as per the UNIX philosophy, so I am not sure how to weigh one against the other.

What do you think, @bugarela?

@bugarela
Copy link
Collaborator

What about doing something more like what TLC does and just produce a pattern without requiring the user to specify it? It takes away the ability of the user to customize the filenames to their liking, but it makes it easier for new users, which won't have to learn how to write this parameter.

So if I run

quint run --out-itf=foo.json --n-traces=2

it will produce foo1.json and foo2.json (or something like that)

@konnov
Copy link
Contributor

konnov commented Aug 22, 2024

What about doing something more like what TLC does and just produce a pattern without requiring the user to specify it? It takes away the ability of the user to customize the filenames to their liking, but it makes it easier for new users, which won't have to learn how to write this parameter.

So if I run

quint run --out-itf=foo.json --n-traces=2

it will produce foo1.json and foo2.json (or something like that)

This actually looks nice to me.

@romac
Copy link
Member Author

romac commented Aug 22, 2024

Agreed, that's perhaps the most user-friendly and pragmatic option 👍

@romac
Copy link
Member Author

romac commented Aug 23, 2024

What shall we do about quint test --output?

  --output       write a trace for every test, e.g., out{#}{}.itf.json where {}
                 is the name of a test, {#} is the test sequence number [string]

Shall we keep the {} placeholder, remove {#} and automatically append the sequence number like for run/verify --out-itf?

@romac
Copy link
Member Author

romac commented Aug 23, 2024

An alternative is to change the placeholders to from {} to {test} and {#} to {seq} or something like that for test, and from {#} to {seq} for run and verify, and automatically append the seq number if the {seq} parameter is not present.

  • quint run/verify --n-traces 3 --out-itf trace_{seq}.itf.json
    • => trace_0.itf.json, trace_1.itf.json, trace_2.itf.json
  • quint run/verify --n-traces 3 --out-itf trace.itf.json
    • => trace0.itf.json, trace1.itf.json, trace2.itf.json
  • quint test --n-traces 3 --output {test}_{seq}.itf.json
    • => someTest_0.itf.json, someTest_1.itf.json, someTest_2.itf.json
  • quint test --n-traces 3 --output {test}.itf.json
    • => someTest0.itf.json, someTest1.itf.json, someTest2.itf.json

This way we get the best of both worlds, being both user-friendly and configurable.

Also, how about we also change test --output to test --out-itf for consistency with run and verify, but keep --output as an alias for --out-itf?

@bugarela
Copy link
Collaborator

I think that would be absolutely amazing! It's a good thing to have the templates optionally, and using seq and test solves the problem of conflict with parallel while also being much clearer. Thanks for thinking this through!

@romac romac changed the title Allow {#} placeholder in run commands --out-itf option, regardless of whether it ends with .itf.json Change placeholders to {test} and {seq}, stop enforcing .itf.json extension, rename test --output to test --out-itf Aug 27, 2024
@romac romac force-pushed the romac/out-itf-option branch from c364762 to 9a5971f Compare August 27, 2024 09:10
@romac romac requested a review from bugarela August 27, 2024 09:10
@romac romac force-pushed the romac/out-itf-option branch from 5963227 to 6f28477 Compare August 27, 2024 11:31
check.sh Outdated
# Loop through each .qnt file and check its header
for file in $qnt_files; do
if [[ "$(head -n 1 "$file")" != "// -*- mode: Bluespec; -*-" ]]; then
echo "File $file does not start with // -*- mode: Bluespec; -*-"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great idea! This will be useful 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Woops forgot to remove this, wanted to do this in a GitHub Actions workflow. Will open a separate PR for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -864,7 +864,7 @@ rm out-itf-example.itf.json

<!-- !test in run with n-traces itf -->
```
quint run --out-itf=out-itf-example.itf.json --n-traces=3 --max-steps=5 --seed=123 ../examples/tutorials/coin.qnt
quint run --out-itf='out-itf-example{seq}.itf.json' --n-traces=3 --max-steps=5 --seed=123 ../examples/tutorials/coin.qnt
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we actually need to update this? Isn't the behavior on the old version of the test still the default?

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad, forgot to revert this!

Copy link
Member Author

Choose a reason for hiding this comment

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

return args.out ? 0 : args.verbosity
}

const Placeholders = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make it fully capitalized? I don't think we have this patter of capitalization for any values in the code (only classes and types), so it's a bit odd.

Suggested change
const Placeholders = {
const PLACEHOLDERS = {

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do

Copy link
Member Author

Choose a reason for hiding this comment

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

if (template.includes(Placeholders.seq)) {
return template.replaceAll(Placeholders.seq, index.toString())
} else if (options.autoAppend && template.endsWith('.itf.json')) {
// Special case for the recommended extension, to avoid adding the index in between `itf` and `json`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is ok, but I guess one alternative would be to add the index right before the first . in the file name, so it would work fine with .itf.json without having to treat it separately, and, although it doesn't matter a lot, it would work better with arbitrary file names (foo1.bla.json is better than foo.bla1.json I guess).

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, that's a better solution!

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@bugarela bugarela left a comment

Choose a reason for hiding this comment

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

🚀

@romac romac enabled auto-merge August 29, 2024 12:17
@romac romac disabled auto-merge August 29, 2024 12:17
@romac romac enabled auto-merge August 29, 2024 12:18
@romac romac merged commit b9f3e4d into main Aug 29, 2024
14 checks passed
@romac romac deleted the romac/out-itf-option branch August 29, 2024 12:22
@bugarela bugarela mentioned this pull request Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants