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

Chore/plot tool cleanup #79

Merged
merged 21 commits into from
Oct 29, 2017
Merged

Chore/plot tool cleanup #79

merged 21 commits into from
Oct 29, 2017

Conversation

naterush
Copy link
Collaborator

@naterush naterush commented Oct 26, 2017

Cleans up the plot tool just a bit. Moves the language from bets -> messages. Also, b/c we now pass in the messages labels, this should be general enough for binary as well w/out any change to the plot tool.

We can now use this display option instead of the report option in a couple places (in both the simulation runner and the testing language). I'm not totally sure how to make the migration over, though - I tried to add arguments to the parser, but was thrashing (new fav word :) ) around for a while. Something about parsing boolean command line args. Would love to get your thoughts @djrtwo

Also, the make_gif function is probably broken as of now -- but it probably can be refactored an simplified in any case.

@@ -76,10 +75,14 @@ def plot(self):
for chains in vals_chain:
edgelist.append(utils.edge(chains, 2, 'blue', 'solid'))

message_lables = {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

spelling --> "labels"

@djrtwo
Copy link
Collaborator

djrtwo commented Oct 26, 2017

Looks like some sanity added! :)

What arguments are you trying to add?
If it's a boolean flag, you can do something like

parser.add_argument(
    '--hide-display',
    help='Hide simulation display',
    action='store_false'
)

args.hide_display

If you use 'store_true' it'll be False unless the flag is used.
If you use 'store_false' it'll be True unless the flag is used.

I imagine this might be what you were wondering

@naterush
Copy link
Collaborator Author

@djrtwo Added a class BlockchainPlotTool that inherits from PlotTool. Essentially, this is the class that deals with building everything that we actually display in the case of the blockchain visualizations.

This moves us closer to being able to easily add binary, as we just have to implement a BinaryPlotTool that inherits from the plot_tool as well. It just keeps track of different things (e.g. does not worry itself with displaying any chains, etc). It might not actually necessary for these BlockchainPlotTool and BinaryPlotTool to inherit from the PlotTool - but let me know what you think.

In any case, this moves simulation runner a lot closer to being totally data-structure-agnostic. The last remaining function that isn't data structure is _check_messages_for_safety. I'm not sure what the best way to make this data-structure-agnostic, either; I think what we describe in the issue about changing check_estimate_safety works (have a last_finalized_estimate instead of block), but I can't figure out how to change how we check for estimate safety in the simulator.

One possible way of doing so it making it so we don't call check_estimate_safety with an actual estimate - we just call it and have the validator handle which estimates to check and how to check them (binary would check just the most recent estimate, and blockchain would check back to the most recent safe block).

I don't love this solution, as it will either b) have a different validator for each data structure (though we can make ) a) require us to implement something like the oracle_manager (but this just pushes the complexity and differences down to a lower level, so I doubt it's worth it).

Also, gif creation now works by default if you add a --save flag. Yay! It's super-duper-janky though (make all these files, then copy them to thumbnails [not sure why :) ], then make the GIF). If you can take a look at things that would be awesome. I'm sure there are probably 100 ways it could be simplified, maybe by using a different library or something.

@naterush
Copy link
Collaborator Author

Not sure if it needs to inherit from PlotTool at all. Might be totally unnecessary.

@djrtwo
Copy link
Collaborator

djrtwo commented Oct 27, 2017

Inheritance on this depends on how much code is generic to plotting in general. Haven't taken a deep look to assess...

As for _check_messages_for_safety, I would offload almost the entire thing to Validator. Something like Validator.update_estimate_safety() which would maybe offload to the view (not sure). The Validator or View run the iterative check for blockchain and the more simple check for Binary.

^^ just read your next paragraph and saw you proposed this. Can we pass the work onto the view rather tahn the validator? Validator consults its View to update it's safety stuff

Not sure if that's clear. we can discuss more later

@djrtwo
Copy link
Collaborator

djrtwo commented Oct 27, 2017

Let me know if/when you want me to review the codez

@djrtwo
Copy link
Collaborator

djrtwo commented Oct 27, 2017

Holy shit, i just looked at BlockchainPlotTool and it's... legible :)



class Network:
"""Simulates a network that allows for message passing between validators."""
def __init__(self, validator_set):
def __init__(self, validator_set, display=True, save=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like network isn't using these two new params

@naterush
Copy link
Collaborator Author

@djrtwo a review now would be awesome. Looking forward to hearing what ya think about the inheritance stuff vs. just importing and using the plot_tool stuff.

Also, the GIF stuff probably can be dramatically cleaned up (but it works, and maybe that's enough for now!). Thanks!

@naterush
Copy link
Collaborator Author

Also, having Validator.update_estimate_safety() seems good. I'm not sure if checking safety (simple binary vs iterative blockchain) belongs in the validator or the view. It seems like both make sense to some degree.

That being said, view is going to have to be implemented for both data structures. If we push the work to view, we can keep the validators totally agnostic to data structure, which would be nice :)

I'm hopping on a flight in 15 minutes. If we agree on this - I'll start implementing! Let me know @djrtwo

@djrtwo
Copy link
Collaborator

djrtwo commented Oct 27, 2017 via email

@djrtwo
Copy link
Collaborator

djrtwo commented Oct 27, 2017 via email

@naterush naterush changed the title [WIP] Chore/plot tool cleanup Chore/plot tool cleanup Oct 27, 2017
@naterush naterush requested a review from djrtwo October 27, 2017 23:40
@naterush naterush mentioned this pull request Oct 27, 2017
djrtwo
djrtwo previously requested changes Oct 28, 2017
Copy link
Collaborator

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

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

  • a handful of comments
  • I see what you mean in that PlotTool could be some functions you import... I think it's fine as is, and it is responsible for knowing about save_paths and report_number and stuff. It rides the line as to overdoing the OO thing.
  • Lint! It's much better than some past PRs but there are some low hanging fruit like unnecessary new lines and stuff.

iterator += 1
if iterator == frame_count_limit:
break
def make_gif(self, frame_count_limit=IMAGE_LIMIT, gif_name="mygif.gif", frame_duration=0.2):
Copy link
Collaborator

Choose a reason for hiding this comment

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

default fame_duration seems a bit too quick. I would use 0.4 or 0.5.

@@ -44,18 +44,26 @@ def main():
'--report-interval', type=int, default=config.getint("ReportInterval"),
help='specifies the interval in rounds at which to plot results'
)
parser.add_argument(
Copy link
Collaborator

Choose a reason for hiding this comment

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

The combo of these two params makes it so vlad doesn't have to click anything for the simulations to move forward :)

Just hide-display and open up the saved gif

self.message_labels = {}


def update(self, message_paths=None, sent_messages=None, new_messages=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this method a lot.

@@ -1,6 +1,6 @@
"""The network module .... """
from casper.view import View
import casper.plot_tool as plot_tool
from casper.plot_tool import PlotTool
Copy link
Collaborator

Choose a reason for hiding this comment

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

imported but not used


graph = nx.Graph()
if save:
graph_path = os.path.dirname(os.path.abspath(__file__)) + '/../graphs/'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move logic to _setup_graph_paths or something. I like to keep __init__ looking clean. It's the method you should be able to look at to get a quick high level view of the object.

graph.add_edges_from([(bets, bets)])
self.report_number = 0

# if there isn't a graph folder, make one!
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove notes

for message in nodes:
if message not in message_colors:
node_color_map[message] = 'white'
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

use elif here instead of else and then a deeper indent

color_mag=self.color_mag,
edges=edgelist
message_labels = {}
for block in self.network.global_view.messages:
Copy link
Collaborator

@djrtwo djrtwo Oct 28, 2017

Choose a reason for hiding this comment

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

We're doing a lot of the same work in BlockchainPlotTool.plot as we are doing in this report method. Can/should the test_lang offload the gathering of stuff to the plot_tool?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call, probably most of it can be refactored into . I'll rework this in a new PR after we get this + the other PR merged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, open up an issue so it doesn't get overlooked

@@ -112,7 +112,4 @@ def check_estimate_safety(self):

# Return the number of faults we can tolerate, which is one less
Copy link
Collaborator

Choose a reason for hiding this comment

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

move comments over to the left

# Return the number of faults we can tolerate, which is one less
# than the number that need to equivocate.
# Return the number of faults we can tolerate, which is one less
# than the number that need to equivocate.
Copy link
Collaborator

Choose a reason for hiding this comment

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

here

@naterush naterush merged commit 9cd5efa into master Oct 29, 2017
@djrtwo djrtwo deleted the chore/plot_tool_cleanup branch October 29, 2017 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants