예제 #1
0
    def test_new_batches(self):
        rest = _RestProxyForTest()
        batches = Batches(rest)

        # Successful run.
        rest.expect_post(
            "/batches", self._check_inputs, 200, {
                'requests': [{
                    'calc_state': 'PENDING',
                    'uuid': '1'
                }, {
                    'calc_state': 'RUNNING',
                    'uuid': '2'
                }]
            })
        states = batches.new_batches(
            [[self.dummy_propagation_params, self.dummy_opm_params],
             [self.dummy_propagation_params, self.dummy_opm_params]])
        self.assertEqual(2, len(states))
        self.assertEqual('1', states[0].get_uuid())
        self.assertEqual('PENDING', states[0].get_calc_state())
        self.assertEqual('2', states[1].get_uuid())
        self.assertEqual('RUNNING', states[1].get_calc_state())

        # Unsuccessful run.
        rest.expect_post("/batches", self._check_inputs, 400, {})
        with self.assertRaises(RuntimeError):
            batches.new_batches(
                [[self.dummy_propagation_params, self.dummy_opm_params],
                 [self.dummy_propagation_params, self.dummy_opm_params]])
    def test_get_summaries(self):
        rest = _RestProxyForTest()
        batches = Batches(rest)

        # Successful request.
        rest.expect_get(
            '/batch?project_uuid=' + self.dummy_propagation_params.get_project_uuid(),
            200,
            {'items': [
                {'uuid': 'aaa', 'calc_state': 'RUNNING'},
                {'uuid': 'bbb', 'calc_state': 'COMPLETED'},
                {'uuid': 'ccc', 'calc_state': 'FAILED'}
            ]})
        summaries = batches.get_summaries(self.dummy_propagation_params.get_project_uuid())
        self.assertEqual(3, len(summaries))
        self.assertEqual('aaa', summaries['aaa'].get_uuid())
        self.assertEqual('RUNNING', summaries['aaa'].get_calc_state())
        self.assertEqual('bbb', summaries['bbb'].get_uuid())
        self.assertEqual('COMPLETED', summaries['bbb'].get_calc_state())
        self.assertEqual('ccc', summaries['ccc'].get_uuid())
        self.assertEqual('FAILED', summaries['ccc'].get_calc_state())

        # Unsuccessful request.
        rest.expect_get(
            '/batch?project_uuid=' + self.dummy_propagation_params.get_project_uuid(), 403, {})
        with self.assertRaises(RuntimeError):
            batches.get_summaries(self.dummy_propagation_params.get_project_uuid())
    def test_new_batch(self):
        rest = _RestProxyForTest()
        batches = Batches(rest)

        # A successful run.
        rest.expect_post("/batch", self._check_input, 200, {'calc_state': 'PENDING', 'uuid': '1'})

        state = batches.new_batch(self.dummy_propagation_params, self.dummy_opm_params)
        self.assertEqual('1', state.get_uuid())
        self.assertEqual('PENDING', state.get_calc_state())

        # Unsuccessful run.
        rest.expect_post("/batch", self._check_input, 400, {'calc_state': 'PENDING', 'uuid': '1'})
        with self.assertRaises(RuntimeError):
            batches.new_batch(self.dummy_propagation_params, self.dummy_opm_params)
예제 #4
0
    def setup(self, url, token, parent_project=None):
        timer = Timer()
        timer.start("Setup")

        self.parent_project = parent_project

        rest = RestRequests(url)
        self.auth = Auth(rest)

        if not self.auth.authorize(token):
            # Try one more time, since often the error is a session expired error and
            # seems to work fine on the second try.
            print("Encountered error, retrying authorization")
            if not self.auth.authorize(token):
                timer.stop()
                return False

        self.rest = AuthorizingRestProxy(rest, self.auth.get_token())
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)

        # Also sets up a project to work in.
        self.project = self.projects.new_project(
            parent_project, None,
            "Test project created at " + str(datetime.datetime.now()))
        print("Set up project with uuid " + self.project.get_uuid())

        timer.stop()
        return True
    def test_get_propagation_results(self):
        rest = _RestProxyForTest()
        batches = Batches(rest)

        # Parts count not specified. No result retrieval is attempted.
        state = StateSummary({
            'uuid': 'aaa',
            'calc_state': 'COMPLETED',
        })
        self.assertIsNone(batches.get_propagation_results(state))

        # Parts count is 0. No result retrieval is attempted.
        state = StateSummary({
            'uuid': 'aaa',
            'calc_state': 'COMPLETED',
            'parts_count': 0,
        })
        self.assertIsNone(batches.get_propagation_results(state))

        # Normal retrieval.
        state = StateSummary({
            'uuid': 'aaa',
            'calc_state': 'COMPLETED',
            'parts_count': 2,
        })
        rest.expect_get('/batch/aaa/1', 200, {'part_index': 'a', 'calc_state': 'RUNNING'})
        rest.expect_get('/batch/aaa/2', 200, {'part_index': 'z', 'calc_state': 'COMPLETED'})
        results = batches.get_propagation_results(state)
        self.assertEqual(2, len(results.get_parts()))
        self.assertEqual('a', results.get_parts()[0].get_part_index())
        self.assertEqual('z', results.get_parts()[1].get_part_index())

        # Some parts could not be found.
        state = StateSummary({
            'uuid': 'aaa',
            'calc_state': 'FAILED',
            'parts_count': 3,
        })
        rest.expect_get('/batch/aaa/1', 404, 'Not json')
        rest.expect_get('/batch/aaa/2', 200, {'part_index': 'z', 'calc_state': 'COMPLETED'})
        rest.expect_get('/batch/aaa/3', 404, 'Not json')
        results = batches.get_propagation_results(state)
        self.assertEqual(3, len(results.get_parts()))
        self.assertIsNone(results.get_parts()[0])
        self.assertEqual('z', results.get_parts()[1].get_part_index())
        self.assertIsNone(results.get_parts()[2])

        # Complete failure.
        state = StateSummary({
            'uuid': 'aaa',
            'calc_state': 'COMPLETED',
            'parts_count': 2,
        })
        rest.expect_get('/batch/aaa/1', 403, 'irrelevant')
        with self.assertRaises(RuntimeError):
            batches.get_propagation_results(state)
예제 #6
0
def propagate_states(state_vectors, epoch_time, end_time):
    """Propagate states from one time to another

    Assume state epoch is the same as integration start time

    Args:
        sate_vectors (list of lists) - list of lists with 6 elements 
                                        [rx, ry, rz, vx, vy, vz]  [km, km/s]
        epoch_time (datetime.datetime) - epoch of state (UTC datetime)
        end_time (datetime.datetime) - time at which to end the simulation
                                        (UTC datetime)

    Returns:
        end_state_vectors (list of lists) - states at end of integration
                                            [rx, ry, rz, vx, vy, vz]  [km, km/s]
    """

    # Convert times to strings
    epoch_time_str = batch_time_string_from_datetime(epoch_time)
    start_time_str = epoch_time_str
    end_time_str = batch_time_string_from_datetime(end_time)
    print("Propagating %i states to propagate from %s to %s" %
          (len(state_vectors), start_time_str, end_time_str))

    url = "https://pro-equinox-162418.appspot.com/_ah/api/adam/v1"
    rest = RestRequests(url)
    batches_module = Batches(rest)

    # Create batches from statevectors
    batches = []
    propagation_params = PropagationParams({
        'start_time':
        start_time_str,
        'end_time':
        end_time_str,
        'project_uuid':
        'ffffffff-ffff-ffff-ffff-ffffffffffff'
    })
    for state_vector in state_vectors:
        opm_params = OpmParams({
            'epoch': start_time_str,
            'state_vector': state_vector
        })
        batches.append(Batch(propagation_params, opm_params))

    # submit batches and wait till they finish running
    BatchRunManager(batches_module, batches).run()

    # Get final states
    end_state_vectors = []
    for batch in batches:
        end_state_vectors.append(batch.get_results().get_end_state_vector())

    return end_state_vectors
예제 #7
0
    def test_delete_batch(self):
        rest = _RestProxyForTest()
        batches = Batches(rest)

        # Successful request.
        rest.expect_delete("/batch/aaa", 204)
        batches.delete_batch('aaa')

        # 200 isn't a valid return value for delete calls right now
        rest.expect_delete("/batch/aaa", 200)
        with self.assertRaises(RuntimeError):
            batches.delete_batch('aaa')
예제 #8
0
    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.config.get_url()))
        auth = Auth(rest)
        if not auth.authenticate(self.config.get_token()):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.config.get_token())
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)

        timer.stop()
        return True
예제 #9
0
    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.url))
        auth = Auth(rest)
        if not auth.authenticate(self.token):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.token)
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True
예제 #10
0
    def setup(self):
        """Sets up the API client and modules for issuing requests to the ADAM API."""
        timer = Timer()
        timer.start("Setup")

        retrying_rest = RetryingRestProxy(RestRequests())
        self.rest = AuthenticatingRestProxy(retrying_rest)
        auth = Auth(self.rest)
        if not auth.authenticate():
            print("Could not authenticate.")
            return False

        self.projects = ProjectsClient(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True
    def test_get_summary(self):
        rest = _RestProxyForTest()
        batches = Batches(rest)

        # Successful request.
        rest.expect_get('/batch/aaa', 200, {'uuid': 'aaa', 'calc_state': 'RUNNING'})
        summary = batches.get_summary('aaa')
        self.assertEqual('aaa', summary.get_uuid())
        self.assertEqual('RUNNING', summary.get_calc_state())

        # Successfully found missing.
        rest.expect_get('/batch/aaa', 404, 'Not JSON wat')
        self.assertIsNone(batches.get_summary('aaa'))

        # Unsuccessful request.
        rest.expect_get('/batch/aaa', 503, 'Also not JSON wat')
        with self.assertRaises(RuntimeError):
            batches.get_summary('aaa')
예제 #12
0
#     'drag_coeff': 2.5,          # object drag coefficient
    
#     'covariance': covariance,   # object covariance
#     'perturbation': 3,          # sigma perturbation on state vector
#     'hypercube': 'FACES',       # hypercube propagation type
    
#     'originator': 'Robot',      # originator of run
#     'object_name': 'TestObj',   # object name
#     'object_id': 'test1234',    # object ID
})
batch = Batch(propagation_params, opm_params)
print("Submitting OPM:")
print(batch.get_opm_params().generate_opm())

# Submit and wait until batch run is ready
batches_module = Batches(auth_rest)
BatchRunManager(batches_module, [batch]).run()

# Get final parts count
parts_count = batch.get_state_summary().get_parts_count()
print("Final state: %s, part count %s\n" % (batch.get_calc_state(), parts_count))

# Get ephemeris of specified part
part_to_get = 0
eph = batch.get_results().get_parts()[part_to_get].get_ephemeris()
print("Ephemeris:")
print(eph)

# Get the end state vector (uncomment to use)
# end_state_vector = batch.get_results().get_end_state_vector()
# print("State vector at the end of propagation:")