Closed adriendilonardo closed 1 year ago
Proposed unit test
def test_paramUpdating():
"""
Test that when the .createUnitary attribute is reassigned to another function, then the ._paramUpdated attribute is set to True
Test that when the .createUnitary attribute is reassigned, the unitary is re-generated upon the next call of .unitary()
"""
qub = qg.Qubit()
unitary = np.random.rand(2, 2)
func = lambda self, collapseOps, decayRate: self.auxDict['unitary'] * 2
qPro = qg.genericProtocol(system=qub, createUnitary=func)
qPro.auxDict['unitary'] = unitary
qPro.unitary()
assert qPro._paramUpdated == False
func = lambda self, collapseOps, decayRate: self.auxDict['unitary'] * 3
qPro.createUnitary = func
assert qPro._paramUpdated == True
assert (np.sum(np.abs(qPro.unitary()-unitary*3)) < 1e-9)
assert qPro._paramUpdated == False
Branch 225-Protocols_not__paramUpdating_on_createUnitary_reassignment created!
Please describe the expected enhancement
When any attribute of parameters of objects relevant in unitary generation are changed, then ._paramUpdated of the protocol should be set to True. The .createUnitary attribute of a protocol points to the function used to generate the unitary, and so ._paramUpdated should be set to True upon its reassignment, which does not currently happen