desihub / desisurvey

Code for desi survey planning and implementation
BSD 3-Clause "New" or "Revised" License
2 stars 7 forks source link

Migrate to single status file; rudimentary afternoon planning; allow tile & status files to not match. #108

Closed schlafly closed 4 years ago

schlafly commented 4 years ago

This PR and an associated one on surveysim reorganizes the desisurvey plan & scheduler state files into a single state file. It also adds rudimentary afternoon planning code which scans for DESI spectra for ETC information and fiberassign directories for available tiles, but I will need to revisit the details of these bits once NERSC is back up. Finally, it allows the derived available exposure & status files to no longer exactly match the tile file---i.e., if we have some weird commissioning TILEIDs, or if we change tile files, etc., that should not cause any issues.

There are also a few miscellaneous changes, like letting NTS be passed an "azrange" argument, which limits selected tiles to a particular azimuth range.

This PR does not make any changes to the actual survey simulations; the same tiles get scheduled at the same times.

The associated PR on surveysim updates surveysim to use the slightly changed API in this patch, primarily to desisurvey.plan.Plan, which now is instantiated with a simulate=True argument if simulated fiber assignment is desired, and which now uses the single state file when --save-restore is requested.

There's more to do here. Some points for discussion:

The equivalent PR on surveysim currently fails testing because it depends on the new API. I'm not sure how to tell CI that it needs to test relative to a special branch.

dkirkby commented 4 years ago

I am a bit concerned about the proliferation of blocks wrapped with if self.simulate: since, ideally, this package should behave identically in real vs simulated ops. There probably indicates that some refactoring between desisurvey and surveysim is needed, which could be in a future PR.

schlafly commented 4 years ago

Let me continue working on this PR to put a few more updates in so that afternoon planning runs on ~real fiberassign and desi raw spectra files. I'll try to get that in this weekend and will hope to merge early next week.

schlafly commented 4 years ago

I added a recent set of commits here that supports afternoon planning like so: python afternoon_plan.py --night 20200611 --config config-cmx.yaml --restore_etc_stats etc_stats_20200610.fits This produces in $DESISURVEY_OUTPUT the directory 20200611 with the following contents:

CMX_58_DITHERED_TILES_Jan2020_s.fits  # the tile file used
config-cmx.yaml  # the config file used, edited to point to this directory
desi-status-20200611.fits  # the status file used
etc_stats-20200611.fits  # the etc_stats file used
rules-cmx.yaml  # the rules file used

These are intended to be all of the files necessary to reproduced afternoon planning results at a later time. We expect that things like the tile file are near-constant, so it may be silly to have a copy of these for each night, but it seems reasonable to expect changes at some point in the survey and copying it into the afternoon planning directory seemed reasonable. Likewise the config.yaml file and rules.yaml file are expected to be unchanged. The etc_status file gives the ETC completion statistics on each tile based on scanning the desi/data/spectro dir, and the desi-status file tracks things like which tiles are available, priorities, etc..

One ugly feature of this model is that one runs afternoon planning pointing to one config / rules / tile file, and then afternoon planning creates new copies of these in the nightly afternoon planning directory. The new config file is then edited to point to the new copies of the rules and tile file. I have some slightly ugly code identifying which lines of the yaml file are the relevant ones to edit, which will be a bit fragile; we could imagine different schemes.

Then the NTS is started pointing to this directory. It should not need any files outside of this directory.

>>> nts = NTS.NTS('20200611/config-cmx.yaml')
>>> nts.next_tile(59012.3, program='CMX_DITHERING')                        
{'tileid': 63138,
 's2n': 50.0,
 'esttime': 12307.54078161631,
 'maxtime': 1200.0,
 'fiber_assign': '/global/cfs/cdirs/desi/target/fiberassign/tiles/trunk/063/fiberassign-063138.fits',
 'foundtile': True}

I have chosen to eliminate the fiber_assign_dir argument to the NTS initializer; this information is now in the config.yaml file. It is needed there anyway so that we can scan to see which fiberassign files are available for observation. I am now defining the "obsplan" argument as pointing to the appropriate config.yaml file for this set of observations, which in turn points to the appropriate rules and tile file in the afternoon planning directory.

I think the above works. Some rough edges we should discuss:

dkirkby commented 4 years ago

Is it still possible to run a surveysim of the nominal 5-year survey after these changes? How about one night of CMX or SV?

I am not too worried about using Configuration.reset() for this very specific use: it is part of the public API after all.

schlafly commented 4 years ago

You can run a 5 year surveysim after merging the corresponding surveysim PR. Reviewing that now, though, it looks like we need to update the rules.yaml file to use the new tile file, for which gray is pass 0. A current 5 year run with the default rules file finishes way too late.

I'll start trying to understand the rules file syntax, but the default rules.yaml file is rather more complicated than the rules-depth.yaml file, so if you're game to update it, please do.

I haven't tried to simulate a night of CMX or SV. Maybe that's useful. I think if I use the usual fiberassign / completeness framework that should be easy, but might not test very much.

schlafly commented 4 years ago

Yes, after fixing the rules file I get what looks like a pretty familiar surveysim run, though I haven't looked at these in a while... the intent was certainly to induce no changes on the simulations. image

schlafly commented 4 years ago

I'm merging this. More can be done, which I've described in the following issues:

However, what's in there should be in a good place for integrating with ICS, which is a higher priority at the moment.