Quantum simulators, machines that can replicate the dynamics of quantum systems, are being built as useful devices and are seen as a stepping stone to universal quantum computers. A key difference between the two is that computers have the ability to perform the logic gates that make up algorithms. We propose a method for learning how to construct these gates efficiently by using the simulator to perform optimal control on itself. This bypasses two major problems of purely classical approaches to the control problem: the need to have an accurate model of the system, and a classical computer more powerful than the quantum one to carry out the required simulations. Strong evidence that the scheme scales polynomially in the number of qubits, for systems of up to 9 qubits with Ising interactions, is presented from numerical simulations carried out in different topologies. This suggests that this in situ approach is a practical way of upgrading quantum simulators to computers.Recent and ongoing work on building large quantum systems is leading to simulators that are able to model physical phenomena, allowing questions about the underlying science to be answered [1][2][3]. These machines contain a register of quantum particles, typically two level quantum systems (qubits) storing quantum information. The presence of interactions between these leads to dynamics that, by varying control parameters in the system Hamiltonian, can replicate the quantum behaviour of systems of interest. This, however, is less general than a quantum computer which is able is to perform a universal set of logic gates on the qubits [4].Provided some control parameters can be varied in time, it is in principle possible to do an arbitrary gate on a quantum many-body system such as a quantum simulator [5][6][7]. Finding the right time-dependency however relies almost exclusively on numerical methods, especially when physical constraints on the control fields are taken into account [8,9]. These methods require a very precise knowledge of the parameters of a system, a daunting task for a machine with a huge number of degrees of freedom. Furthermore, they are intractable on a classical computer if the quantum simulator we want to solve the problem for is large enough to do something beyond the capabilities of classical computers. These two difficulties provide a major obstacle in using quantum simulators to perform arbitrary computation.We circumvent these problems by showing how well-known existing numerical methods can be translated to run in situ on the quantum simulator itself, as illustrated in Fig.1. A mix of an-