CirQuS-UTS / QuanGuru

QuanGuru (pronounced Kangaroo) is a Python library for numerical modelling of quantum systems. It is still under-development, and it consists of tools for numerical simulations of Quantum systems.
BSD 3-Clause "New" or "Revised" License
5 stars 7 forks source link

Protocols not ._paramUpdating on .createUnitary reassignment #225

Closed adriendilonardo closed 1 year ago

adriendilonardo commented 1 year ago

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

adriendilonardo commented 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
github-actions[bot] commented 1 year ago

Branch 225-Protocols_not__paramUpdating_on_createUnitary_reassignment created!