Skip to content

Add a default rule for custom blocks #3570

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

radhakrishnatg
Copy link

Fixes # .

Summary/Motivation:

Add a default rule for custom blocks. With this default rule, construction of custom blocks becomes easier.

@declare_custom_block(FooBlock)
class FooBlockData(BlockData):
    def build(self, *args, option_1, option_2):
        self.x = Var()
        self.y = Param(initialize=option_1)
        
        
m.blk = FooBlock([1, 2, 3], options={"option_1": 1, "option_2": 2})

Implementing build method is optional. If it is not implemented, an empty block will be returned.
Users can overwrite the default build method by passing the rule argument:
m.blk = FooBlock([1, 2, 3], rule=my_custom_block_rule) # Ignores the build method

Changes proposed in this PR:

  • Added default rule argument to the declare_custom_block decorator
  • Added tests to cover the changes.

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@blnicho blnicho requested a review from jsiirola April 29, 2025 18:50
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