Thank you for your advices.
My program appears to be working.
Writing for the knowledge of younger students, I have corrected this:
before
state_batch = torch.cat(batch.state) 
non_final_next_states = torch.cat([s for s in batch.next_state
                                                    if s is not None])

after
state_batch = torch.stack(batch.state) 
non_final_next_states = torch.stack([s for s in batch.next_state

                                                    if s is not None])