-
Notifications
You must be signed in to change notification settings - Fork 125
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
Allow using const values in agent macro #831
Conversation
Codecov Report
@@ Coverage Diff @@
## main #831 +/- ##
==========================================
+ Coverage 70.13% 70.17% +0.04%
==========================================
Files 42 42
Lines 2719 2723 +4
==========================================
+ Hits 1907 1911 +4
Misses 812 812
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Implemented the first way described in #728 using Agents
@agent A NoSpaceAgent begin
f1::Int
f2::Int
consts = (:f1, :f2)
end
agent = A(1, 3, 5)
agent.f1 = 10 returns ERROR: setfield!: const field .f1 of type A cannot be changed
Stacktrace:
[1] setproperty!(x::A, f::Symbol, v::Int64)
@ Base .\Base.jl:38
[2] top-level scope
@ REPL[4]:1 |
this should be it, all new tests pass! |
does it allow inhereting from a type defined with constants? if we change |
Yes it allows it, any const will be propagated to any inheriting new type, this is so because we actually check if there are any const field in the base type and then add it as a const also in the new type |
ok great! |
why isn't it possible to do things the native julia way and allow prefacing with |
yes, a field name consts is disallowed, there is no way to have const inside the agent macro unfortunately due to parsing errors I think, see JuliaLang/julia#45024 |
it's a bit hacky yes but it's a way not to redefine the agent macro as was done in #728, we could follow that path alternatevely but this means that every code will break :D |
but the julia issue you cite is fixed...? |
Okay, I see, there is no way to have But, rename it to @Tortar this is a big change. please do not tag anything after mergfing the const and keyword improvements. i want to read the final docstring and changelog and give the ok for a new tag. |
yes, but the fix is disallowing the construct :D
Il Sab 22 Lug 2023, 11:59 George Datseris ***@***.***> ha
scritto:
… but the julia issue you cite is fixed...?
—
Reply to this email directly, view it on GitHub
<#831 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQH6VX2MLVPWHNC7I3KC4ELXROP6JANCNFSM6AAAAAA2KZPRPI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
sure, I actually have another important change which I would like to finish up, we should probably tag them all together |
@Datseris I completed the higlighting of the changes reverting some of the changed lines in https://github.com/JuliaDynamics/Agents.jl/pull/732/files , I also declared the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great. Simple comments to address and then please merge (BUT NNOT TAG!!!)
Co-authored-by: George Datseris <[email protected]>
Merging! (Not tagging :D) |
This should make it possible to use default values addressing #709 , let me know what do you think.Experimenting a bit, there shouldn't be any perf regression applying @kwdef as default(I also put in the api page of the documentation the replicate! function, forgot to do that in the other pr :D)edit: now it also includes the possibility to declare constants, which should help performance, but need some good tests