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

Autumn cleaning part 3 - split transactron/core.py #471

Closed
wants to merge 9 commits into from

Conversation

lekcyjna123
Copy link
Contributor

Here is proposition to split core.py into smaller parts. Tests don't work yet (particularly I haven't started to solve circular imports yet). Please comment about split and naming.

Method, Transaction, TransactionBase, TransactionManager are very big classes, so I decided that each of them will be in separate file.

@lekcyjna123
Copy link
Contributor Author

lekcyjna123 commented Oct 7, 2023

There were needed some changes in transactron code to break cyclic references. Some of them are imports inside functions instead of top level imports. Affected functions:

  • MethodMap.transactions_for
  • Transaction.__init__
  • TransactionBase.context

The alternative is to use absolute names, which will be ugly in my opinion.

@lekcyjna123 lekcyjna123 marked this pull request as ready for review October 7, 2023 17:36
Copy link
Member

@tilk tilk left a comment

Choose a reason for hiding this comment

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

I feel this is too fine-grained, and I very much don't like how cyclic dependencies are handled. This might complicate altering the Transactron core in the future.

transactron/core/relation_database.py Outdated Show resolved Hide resolved
transactron/core/schedulers.py Outdated Show resolved Hide resolved
transactron/core/transaction.py Outdated Show resolved Hide resolved
transactron/core/transaction.py Outdated Show resolved Hide resolved
Comment on lines 115 to 116
from .method import Method
from .transaction import Transaction
Copy link
Member

Choose a reason for hiding this comment

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

This will be resolved by putting Method, Transaction and TransactionBase in a single file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like the idea to put Method, Transaction and TransactionBase to single file. Such file will be big (over 500 lines).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I start to think if our type hints are correct. In TransactionBase we make some assumptions about subclasses. We allow only Transaction and Method subclass, so we are leaking the abstraction. The type hint TransactionOrMethod is from the time before creating TransactionBase.
c87bb31
So in my opinion we should use TransactionBase type instead of TransactionOrMethod.

Copy link
Member

Choose a reason for hiding this comment

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

So in my opinion we should use TransactionBase type instead of TransactionOrMethod.

No, this is wrong. TransactionBase is an open type, TransactionOrMethod is a closed one. Or: if you know that a TransactionOrMethod is not a Transaction, it must be a Method. There is no such guarantee for TransactionBase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. There is no such guarantee on type level, but if we need it, then the code is wrongly designed. In base class these should be defined only code, which is common for all its subclasses. So limiting it to only TransactionOrMethod suggest, that it wouldn't be common for other subclasses, so it shouldn't be in base class.

Copy link
Member

Choose a reason for hiding this comment

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

You seem to misunderstand. The transaction manager works on transactions and methods only, and the TransactionOrMethod type tells the typechecker exactly that. Your change messed this up, see e.g. lines 52-55 in manager.py.

transactron/core/relation_database.py Outdated Show resolved Hide resolved
@tilk tilk added refactor Doesn't change functionality, but makes stuff nicer transactions Transaction framework labels Oct 7, 2023
@lekcyjna123
Copy link
Contributor Author

lekcyjna123 commented Oct 8, 2023

Second proposition has been just uploaded. Method, Transaction and TransactionBase still are in separate files. But imports from insides functions have been removed. This removal was possible because of:

  • Change of type hints from TransactionOrMethod to TransactionBase (in MethodMap, TransactionBase, Relation and RelationBase)
  • Moving TransactionContext to creators

Changes:

  • modules.py have been renamed to creators.py (because of moving to that file def_method and TransactionContext)
  • sugar.py has been removed
  • relation_database.py has been removed

@tilk
Copy link
Member

tilk commented Oct 8, 2023

I think that this looks much better than the initial proposal. Would like to get a second opinion before deciding.

if isinstance(elem, Transaction):
return [elem]
else:
assert isinstance(elem, Method)
Copy link
Member

Choose a reason for hiding this comment

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

This is silly. Original type already told the typechecker that this is the only option here.

@tilk
Copy link
Member

tilk commented Oct 8, 2023

The big problem with this PR is that I see NO WAY to check what actual changes were made to the code, so there is no way to review them.

run = Signal()
m.d.comb += run.eq(run_val)
else:
assert isinstance(source, Transaction)
Copy link
Member

Choose a reason for hiding this comment

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

Again, you silently added this assert.

@lekcyjna123
Copy link
Contributor Author

The big problem with this PR is that I see NO WAY to check what actual changes were made to the code, so there is no way to review them.

Yes, it is the problem and the reason why I wanted to have all split to small PR. I have two ideas:

  • I can create separate PR in which I will introduce all needed modification without moving files
  • You can compare first commit in this review with the newest. I did moves in the first, so all other contain changes which were needed to make the code works.

@tilk
Copy link
Member

tilk commented Oct 8, 2023

You can compare first commit in this review with the newest. I did moves in the first, so all other contain changes which were needed to make the code works.

Unfortunately, some of your later commits contain both moves and code changes, e.g. "Remove relation database". As you smuggled weakening of the type guarantees in the most fundamental code in this project there, I'm now becoming paranoid with regard to your changes.

@lekcyjna123
Copy link
Contributor Author

Ok. So I will try to split the changes to separate PR without any moves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Doesn't change functionality, but makes stuff nicer transactions Transaction framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants