human
Complete the below
def change_node_state(deployer, desired_configuration):

    ''''Change the local state to match the given desired state.
    :param IDeployer deployer: Deployer to discover local state and
    calculate changes.
    :param Deployment desired_configuration: The intended configuration of all
    nodes.
    :return: ``Deferred`` that fires when the necessary changes are done.'
    '''

Can you provide a Python code to calculate changes?
assistant
#Here is Python code to calculate changes.
    state_persister = InMemoryStatePersister()
    def converge():
        d = deployer.discover_state(DeploymentState(nodes={NodeState(hostname=deployer.hostname, uuid=deployer.node_uuid, applications=[], manifestations={}, paths={}, devices={})}), persistent_state=state_persister.get_state())
        def got_changes(local_state):
            changes = local_state.shared_state_changes()
            cluster_state = DeploymentState()
            for change in changes:
                cluster_state = change.update_cluster_state(cluster_state)
            return deployer.calculate_changes(desired_configuration, cluster_state, local_state)
        d.addCallback(got_changes)
        d.addCallback((lambda change: run_state_change(change, deployer=deployer, state_persister=state_persister)))
        return d
    result = converge()
    result.addCallback((lambda _: converge()))
    result.addCallback((lambda _: converge()))
    return result