Esempio n. 1
0
 def setup(self,
           numTrajectoriesPerSim,
           trajectoryLength,
           simulationParamsIn={},
           cliffordParamsIn={},
           terrainMapParamsIn={},
           terrainParamsIn={},
           senseParamsIn={}):
     # start sim
     physicsClientId = p.connect(p.DIRECT)
     # initialize clifford robot
     robot = Clifford(params=cliffordParams,
                      physicsClientId=physicsClientId)
     # initialize simulation controller
     self.sim = simController(robot,
                              simulationParamsIn=simulationParamsIn,
                              senseParamsIn=senseParamsIn,
                              terrainMapParamsIn=terrainMapParamsIn,
                              terrainParamsIn=terrainParamsIn,
                              physicsClientId=physicsClientId)
     data = self.sim.controlLoopStep([0, 0])
     bufferLength = numTrajectoriesPerSim * trajectoryLength
     self.replayBuffer = sequentialReplayBuffer(bufferLength, data[0],
                                                data[1])
     self.trajectoryLength = trajectoryLength
     self.numTrajectoriesPerSim = numTrajectoriesPerSim
            reconstruction[0], input[0]) + F.mse_loss(
                reconstruction[1], input[1]) + F.mse_loss(
                    reconstruction[2], input[2])
        KLD = -0.5 * torch.sum(1 + latentLogVar - latentMu.pow(2) -
                               latentLogVar.exp())
        totalLoss = self.reconstructionLossWeight * reconstructionLoss + self.KLDWeight * KLD
        return totalLoss, reconstructionLoss, KLD


if __name__ == '__main__':
    # check if cuda available
    device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
    writer = SummaryWriter()

    # load replay buffer
    cpuReplayBuffer = sequentialReplayBuffer(loadDataPrefix='simData/v2')
    cpuReplayBuffer.loadData()
    # remove all joint states
    cpuReplayBuffer.inputData[0] = cpuReplayBuffer.inputData[0][:, 0:-14]
    cpuReplayBuffer.inputData[3] = cpuReplayBuffer.inputData[3][:, 0:-14]
    cpuReplayBuffer.outputData[0] = cpuReplayBuffer.outputData[0][:, 0:-14]
    inStateDim = 9  # (3 gravity vector) + (6 twist)
    inMapDim = cpuReplayBuffer.inputData[1].shape[2]
    inActionDim = cpuReplayBuffer.inputData[2].shape[1]
    outStateDim = 13  # (7 relative position) + (6 twist)
    latentDim = 32

    # training/ neural network parameters
    learningRate = 0.00025
    lrDecay_stepSize = 10000
    lrDecay_gamma = 0.9
Esempio n. 3
0
 sims = []
 replayBuffers = []
 # set up simulations
 for i in range(numParallelSims):
     if i == -1:
         physicsClientId = p.connect(p.GUI)
     else:
         physicsClientId = p.connect(p.DIRECT)
     sims.append(
         simController(timeStep=1. / 500.,
                       stepsPerControlLoop=50,
                       numSolverIterations=300,
                       physicsClientId=physicsClientId))
     data = sims[-1].controlLoopStep([0, 0])
     replayBuffers.append(
         sequentialReplayBuffer(replayBufferLength, data[0], data[1]))
 allDataReplayBuffer = sequentialReplayBuffer(replayBufferLength *
                                              numParallelSims,
                                              data[0],
                                              data[1],
                                              saveDataPrefix='simData/v2')
 executor = concurrent.futures.ProcessPoolExecutor()
 results = executor.map(runSim, [[sims[i], replayBuffers[i]]
                                 for i in range(numParallelSims)])
 for otherBuffer in results:
     print(otherBuffer.bufferIndex)
     if otherBuffer.bufferFilled:
         allDataReplayBuffer.inheritData(otherBuffer)
     else:
         print("one buffer not filled")
 allDataReplayBuffer.saveData()