entropicalabs / openqaoa

Multi-backend SDK for quantum optimisation
MIT License
116 stars 58 forks source link

Raise error when changing workflow properties after compilation #199

Closed raulconchello closed 1 year ago

raulconchello commented 1 year ago

Implemented a new decorator for the setter methods of the workflows.

This decorator will check if the workflow is compiled, if it is then raises an error.

The decorator is the following:

def check_compiled(func):
    def wrapper(self, *args, **kwargs):
        result = func(self, *args, **kwargs)
        if self.compiled:
            raise ValueError("Cannot change properties of the object after compilation.")
        return result
    return wrapper

Tests implemented too

codecov[bot] commented 1 year ago

Codecov Report

Merging #199 (1e66c0e) into dev (9d39cb1) will increase coverage by 0.05%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev     #199      +/-   ##
==========================================
+ Coverage   88.79%   88.84%   +0.05%     
==========================================
  Files          32       32              
  Lines        5799     5827      +28     
==========================================
+ Hits         5149     5177      +28     
  Misses        650      650              
Impacted Files Coverage Δ
tests/test_analytical_simulator.py 100.00% <100.00%> (ø)
tests/test_workflows.py 99.51% <100.00%> (+0.01%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more