Runs a temperature simulation. This will simulate an object at temperature `initial_temperature` sitting at rest in a large room at temperature `ambient_temperature`. The object has some intrinsic `heat_coefficient`, which indicates how much thermal conductivity it has: for instance
(logdir, session_id, hparams, group_name)
| 145 | |
| 146 | |
| 147 | def run(logdir, session_id, hparams, group_name): |
| 148 | """Runs a temperature simulation. |
| 149 | |
| 150 | This will simulate an object at temperature `initial_temperature` |
| 151 | sitting at rest in a large room at temperature `ambient_temperature`. |
| 152 | The object has some intrinsic `heat_coefficient`, which indicates |
| 153 | how much thermal conductivity it has: for instance, metals have high |
| 154 | thermal conductivity, while the thermal conductivity of water is low. |
| 155 | |
| 156 | Over time, the object's temperature will adjust to match the |
| 157 | temperature of its environment. We'll track the object's temperature, |
| 158 | how far it is from the room's temperature, and how much it changes at |
| 159 | each time step. |
| 160 | |
| 161 | Arguments: |
| 162 | logdir: the top-level directory into which to write summary data |
| 163 | session_id: an id for the session. |
| 164 | hparams: A dictionary mapping a hyperparameter name to its value. |
| 165 | group_name: an id for the session group this session belongs to. |
| 166 | """ |
| 167 | tf.reset_default_graph() |
| 168 | tf.set_random_seed(0) |
| 169 | |
| 170 | initial_temperature = hparams["initial_temperature"] |
| 171 | ambient_temperature = hparams["ambient_temperature"] |
| 172 | heat_coefficient = HEAT_COEFFICIENTS[hparams["material"]] |
| 173 | session_dir = os.path.join(logdir, session_id) |
| 174 | writer = tf.summary.FileWriter(session_dir) |
| 175 | writer.add_summary( |
| 176 | summary.session_start_pb(hparams=hparams, group_name=group_name) |
| 177 | ) |
| 178 | writer.flush() |
| 179 | with tf.name_scope("temperature"): |
| 180 | # Create a mutable variable to hold the object's temperature, and |
| 181 | # create a scalar summary to track its value over time. The name of |
| 182 | # the summary will appear as 'temperature/current' due to the |
| 183 | # name-scope above. |
| 184 | temperature = tf.Variable( |
| 185 | tf.constant(initial_temperature), name="temperature" |
| 186 | ) |
| 187 | scalar_summary.op( |
| 188 | "current", |
| 189 | temperature, |
| 190 | display_name="Temperature", |
| 191 | description="The temperature of the object under " |
| 192 | "simulation, in Kelvins.", |
| 193 | ) |
| 194 | |
| 195 | # Compute how much the object's temperature differs from that of its |
| 196 | # environment, and track this, too: likewise, as |
| 197 | # 'temperature/difference_to_ambient'. |
| 198 | ambient_difference = temperature - ambient_temperature |
| 199 | scalar_summary.op( |
| 200 | "difference_to_ambient", |
| 201 | ambient_difference, |
| 202 | display_name="Difference to ambient temperature", |
| 203 | description=( |
| 204 | "The difference between the ambient " |