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

"Set" classes are not iterable #65

Open
awendelin-work opened this issue Jul 2, 2024 · 0 comments
Open

"Set" classes are not iterable #65

awendelin-work opened this issue Jul 2, 2024 · 0 comments

Comments

@awendelin-work
Copy link
Contributor

The Set classes, ExperimentSet, TraceSet, ConfigurationParameterDescriptorSet, ConfigurationSet, ConfigurationSourceSet and OutputDescriptorSet are not usable by themselves as collections.

This gives you access patterns like:

from tsp.trace_set import TraceSet

traces = TraceSet([{"name": "trace0"}, {"name": "trace1"}])

for trace in traces.traces:
    print(t.name)
# trace0
# trace1

print(len(traces.traces))
# 2

This is especially inconvenient when working with experiments, since to loop over traces, you must do:

for t in experiment.traces.traces

We could make the classes easier to work with by making them implement collection interfaces.

This would give you the following access patterns instead:

from tsp.trace_set import TraceSet

traces = TraceSet([{"name": "trace0"}, {"name": "trace1"}])

for trace in traces:
    print(t.name)
# trace0
# trace1

print(len(traces))
# 2

See example in this commit.

__getitem__ could be implemented as well to allow indexing with integers (traces[0]), but it is not implemented for Python sets, so it would make the "Set" classes look less like sets.

If this kind of functionality is wanted, I can help provide patches.

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

No branches or pull requests

1 participant