-
Notifications
You must be signed in to change notification settings - Fork 4.3k
SideChannel helpers #3596
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
SideChannel helpers #3596
Conversation
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.
I think an OutgoingMessage and IncomingMessage makes more sense than a byte[].
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.
Ditto what Vince said. I think this abstraction makes a lot of sense.
return str; | ||
} | ||
|
||
public IList<float> ReadFloatArray() |
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.
Why not a float[]?
Not sure we need this method to be honest.
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.
I added it on the python side in response to @awjuliani's comment on the doc.
float[]
implements the IList<float>
interface; I figured it was better to be a bit more generic in case we ever wanted to change the underlying implementation.
com.unity.ml-agents/Runtime/SideChannels/FloatPropertiesChannel.cs
Outdated
Show resolved
Hide resolved
public void SetRawBytes(byte[] data) | ||
{ | ||
m_Stream.Seek(0, SeekOrigin.Begin); | ||
m_Stream.Write(data, 0, data.Length); |
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.
If the stream was created with an array that was larger than the one passed it, won't the stream be corrupted after this?
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.
Good catch. I think m_Stream.SetLength(0)
should fix this (and setting capacity as an optimization too).
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.
Added a unit test and confirmed fixed.
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.
don't you always want the capacity to be data.Length
?
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.
I didn't want to shrink capacity if we didn't need to.
} | ||
} | ||
|
||
/// <summary> |
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.
Put in a separate file
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.
Yeah, makes sense, wasn't sure where to draw the line.
} | ||
} | ||
|
||
/// <summary> |
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.
Put in separate file
Proposed change(s)
Utilities for incoming and outgoing sidechannel messages. Still requires the user to make sure fields are written in a consistent order, but means that they never have to deal with bytes or struct pack/unpack directly.
This is still a work in progress; if you think this will be useful, I can add more methods and add some actual docstrings/update the docs. Can also add similar abstractions on the C# side if they'd be helpful.
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
Types of change(s)
Checklist
Other comments