Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 57169e68d275
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bae4f883e7ab
Choose a head ref
  • 9 commits
  • 10 files changed
  • 1 contributor

Commits on Aug 29, 2021

  1. Reorder parameters.

    pleroy committed Aug 29, 2021
    Copy the full SHA
    560b881 View commit details
  2. More parameter reordering.

    pleroy committed Aug 29, 2021
    Copy the full SHA
    d81c2b8 View commit details
  3. Add and propagate after_time.

    pleroy committed Aug 29, 2021
    Copy the full SHA
    1f6a35a View commit details
  4. Use after_time.

    pleroy committed Aug 29, 2021
    Copy the full SHA
    c96ea43 View commit details
  5. A test.

    pleroy committed Aug 29, 2021
    Copy the full SHA
    89d3e29 View commit details
  6. After egg's review.

    pleroy committed Aug 29, 2021
    Copy the full SHA
    6056ed3 View commit details
  7. Compilation error.

    pleroy committed Aug 29, 2021
    Copy the full SHA
    6638c54 View commit details
  8. A test found a bug.

    pleroy committed Aug 29, 2021
    Copy the full SHA
    cb6def0 View commit details
  9. Merge pull request #3120 from pleroy/PartialSerialization

    Partial serialization of DiscreteTrajectory
    pleroy authored Aug 29, 2021
    Copy the full SHA
    bae4f88 View commit details
6 changes: 3 additions & 3 deletions ksp_plugin/part.cpp
Original file line number Diff line number Diff line change
@@ -252,10 +252,10 @@ void Part::WriteToMessage(not_null<serialization::Part*> const message,
serialization_index_for_pile_up(containing_pile_up_.get()));
}
rigid_motion_.WriteToMessage(message->mutable_rigid_motion());
prehistory_->WriteToMessage(message->mutable_prehistory(),
/*excluded=*/{},
prehistory_->WriteToMessage(/*excluded=*/{},
/*tracked=*/{history_, psychohistory_},
/*exact=*/{});
/*exact=*/{},
message->mutable_prehistory());
}

not_null<std::unique_ptr<Part>> Part::ReadFromMessage(
6 changes: 3 additions & 3 deletions ksp_plugin/pile_up.cpp
Original file line number Diff line number Diff line change
@@ -181,10 +181,10 @@ void PileUp::WriteToMessage(not_null<serialization::PileUp*> message) const {
for (not_null<Part*> const part : parts_) {
message->add_part_id(part->part_id());
}
history_->WriteToMessage(message->mutable_history(),
/*excluded=*/{},
history_->WriteToMessage(/*excluded=*/{},
/*tracked=*/{psychohistory_},
/*exact=*/{});
/*exact=*/{},
message->mutable_history());
for (auto const& [part, rigid_motion] : actual_part_rigid_motion_) {
rigid_motion.WriteToMessage(&(
(*message->mutable_actual_part_rigid_motion())[part->part_id()]));
18 changes: 9 additions & 9 deletions ksp_plugin/vessel.cpp
Original file line number Diff line number Diff line change
@@ -466,10 +466,10 @@ void Vessel::WriteToMessage(not_null<serialization::Vessel*> const message,
message->add_kept_parts(part_id);
}
// Starting with Gateaux we don't save the prediction, see #2685.
history_->WriteToMessage(message->mutable_history(),
/*exclude=*/{prediction_},
history_->WriteToMessage(/*excluded=*/{prediction_},
/*tracked=*/{backstory_, psychohistory_},
/*exact=*/{});
/*exact=*/{},
message->mutable_history());
if (flight_plan_ != nullptr) {
flight_plan_->WriteToMessage(message->mutable_flight_plan());
}
@@ -619,16 +619,16 @@ Checkpointer<serialization::Vessel>::Writer Vessel::MakeCheckpointerWriter() {
return [this](not_null<serialization::Vessel::Checkpoint*> const message) {
lock_.AssertReaderHeld();
if (backstory_ == history_.get()) {
history_->WriteToMessage(message->mutable_non_collapsible_segment(),
/*excluded=*/{psychohistory_},
history_->WriteToMessage(/*excluded=*/{psychohistory_},
/*tracked=*/{},
/*exact=*/{psychohistory_->Fork()});
/*exact=*/{psychohistory_->Fork()},
message->mutable_non_collapsible_segment());
} else {
auto backstory = backstory_->DetachFork();
backstory->WriteToMessage(message->mutable_non_collapsible_segment(),
/*excluded=*/{psychohistory_},
backstory->WriteToMessage(/*excluded=*/{psychohistory_},
/*tracked=*/{},
/*exact=*/{psychohistory_->Fork()});
/*exact=*/{psychohistory_->Fork()},
message->mutable_non_collapsible_segment());
history_->AttachFork(std::move(backstory));
}

26 changes: 20 additions & 6 deletions physics/discrete_trajectory.hpp
Original file line number Diff line number Diff line change
@@ -172,10 +172,22 @@ class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,
// entry; otherwise, they must be direct or indirect forks of this trajectory.
// The points denoted by |exact| are written and re-read exactly and are not
// affected by any errors introduced by zfp compression.
void WriteToMessage(not_null<serialization::DiscreteTrajectory*> message,
std::set<DiscreteTrajectory const*> const& excluded,
std::vector<DiscreteTrajectory const*> const& tracked,
std::vector<Iterator> const& exact) const;
void WriteToMessage(
std::set<DiscreteTrajectory const*> const& excluded,
std::vector<DiscreteTrajectory const*> const& tracked,
std::vector<Iterator> const& exact,
not_null<serialization::DiscreteTrajectory*> message) const;
// Same as above, but only serializes the forks, points and downsampling data
// with time greater than or equal to |after_time|. Note that the client must
// ensure that the forks in |excluded| and |tracked| are after the given time.
// It is always possible to track this object itself.
void WriteToMessage(
Instant const& after_time,
std::set<DiscreteTrajectory const*> const& excluded,
std::vector<DiscreteTrajectory const*> const& tracked,
std::vector<Iterator> const& exact,
not_null<serialization::DiscreteTrajectory*> message) const;


// |forks| must have a size appropriate for the |message| being deserialized
// and the orders of the |forks| must be consistent during serialization and
@@ -239,6 +251,7 @@ class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,
std::vector<TimelineConstIterator> ExtractDenseIterators();

void WriteToMessage(
Instant const& after_time,
not_null<serialization::DiscreteTrajectory::Downsampling*> message)
const;
static Downsampling ReadFromMessage(
@@ -273,9 +286,10 @@ class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,
// This trajectory need not be a root. Returns false if this trajectory is
// excluded.
bool WriteSubTreeToMessage(
not_null<serialization::DiscreteTrajectory*> message,
Instant const& after_time,
std::set<DiscreteTrajectory const*>& excluded,
std::vector<DiscreteTrajectory const*>& tracked) const;
std::vector<DiscreteTrajectory const*>& tracked,
not_null<serialization::DiscreteTrajectory*> message) const;

void FillSubTreeFromMessage(
serialization::DiscreteTrajectory const& message,
65 changes: 42 additions & 23 deletions physics/discrete_trajectory_body.hpp
Original file line number Diff line number Diff line change
@@ -328,15 +328,25 @@ DegreesOfFreedom<Frame> DiscreteTrajectory<Frame>::EvaluateDegreesOfFreedom(

template<typename Frame>
void DiscreteTrajectory<Frame>::WriteToMessage(
not_null<serialization::DiscreteTrajectory*> const message,
std::set<DiscreteTrajectory const*> const& excluded,
std::vector<DiscreteTrajectory const*> const& tracked,
std::vector<Iterator> const& exact) const {
std::vector<Iterator> const& exact,
not_null<serialization::DiscreteTrajectory*> const message) const {
WriteToMessage(InfinitePast, excluded, tracked, exact, message);
}

template<typename Frame>
void DiscreteTrajectory<Frame>::WriteToMessage(
Instant const& after_time,
std::set<DiscreteTrajectory const*> const& excluded,
std::vector<DiscreteTrajectory const*> const& tracked,
std::vector<Iterator> const& exact,
not_null<serialization::DiscreteTrajectory*> const message) const {
CHECK(this->is_root());

std::set<DiscreteTrajectory<Frame> const*> mutable_excluded = excluded;
std::vector<DiscreteTrajectory<Frame> const*> mutable_tracked = tracked;
WriteSubTreeToMessage(message, mutable_excluded, mutable_tracked);
WriteSubTreeToMessage(after_time, mutable_excluded, mutable_tracked, message);
CHECK(std::all_of(mutable_excluded.begin(),
mutable_excluded.end(),
[](DiscreteTrajectory<Frame> const* const fork) {
@@ -509,6 +519,7 @@ DiscreteTrajectory<Frame>::Downsampling::ExtractDenseIterators() {

template<typename Frame>
void DiscreteTrajectory<Frame>::Downsampling::WriteToMessage(
Instant const& after_time,
not_null<serialization::DiscreteTrajectory::Downsampling*> const message)
const {
message->set_max_dense_intervals(max_dense_intervals_);
@@ -518,7 +529,10 @@ void DiscreteTrajectory<Frame>::Downsampling::WriteToMessage(
// const.
start_time_.value().WriteToMessage(message->add_dense_timeline());
for (int i = 1; i < dense_iterators_.size(); ++i) {
dense_iterators_[i]->first.WriteToMessage(message->add_dense_timeline());
Instant const& time = dense_iterators_[i]->first;
if (time >= after_time) {
time.WriteToMessage(message->add_dense_timeline());
}
}
}
}
@@ -572,19 +586,19 @@ void DiscreteTrajectory<Frame>::Downsampling::UpdateStartTimeIfNeeded() {

template<typename Frame>
bool DiscreteTrajectory<Frame>::WriteSubTreeToMessage(
not_null<serialization::DiscreteTrajectory*> const message,
Instant const& after_time,
std::set<DiscreteTrajectory const*>& excluded,
std::vector<DiscreteTrajectory const*>& tracked) const {
std::vector<DiscreteTrajectory const*>& tracked,
not_null<serialization::DiscreteTrajectory*> const message) const {
bool const included =
Forkable<DiscreteTrajectory, Iterator, DiscreteTrajectoryTraits<Frame>>::
WriteSubTreeToMessage(message, excluded, tracked);
WriteSubTreeToMessage(after_time, excluded, tracked, message);
if (!included) {
return false;
}

int const timeline_size = timeline_.size();
int timeline_size = timeline_.size();
auto* const zfp = message->mutable_zfp();
zfp->set_timeline_size(timeline_size);

// The timeline data is made dimensionless and stored in separate arrays per
// coordinate. We expect strong correlations within a coordinate over time,
@@ -606,21 +620,26 @@ bool DiscreteTrajectory<Frame>::WriteSubTreeToMessage(
std::optional<Instant> previous_instant;
Time max_Δt;
std::string* const zfp_timeline = zfp->mutable_timeline();
for (auto const& [instant, degrees_of_freedom] : timeline_) {
auto const q = degrees_of_freedom.position() - Frame::origin;
auto const p = degrees_of_freedom.velocity();
t.push_back((instant - Instant{}) / Second);
qx.push_back(q.coordinates().x / Metre);
qy.push_back(q.coordinates().y / Metre);
qz.push_back(q.coordinates().z / Metre);
px.push_back(p.coordinates().x / (Metre / Second));
py.push_back(p.coordinates().y / (Metre / Second));
pz.push_back(p.coordinates().z / (Metre / Second));
if (previous_instant.has_value()) {
max_Δt = std::max(max_Δt, instant - *previous_instant);
for (auto const& [time, degrees_of_freedom] : timeline_) {
if (time < after_time) {
--timeline_size;
} else {
auto const q = degrees_of_freedom.position() - Frame::origin;
auto const p = degrees_of_freedom.velocity();
t.push_back((time - Instant{}) / Second);
qx.push_back(q.coordinates().x / Metre);
qy.push_back(q.coordinates().y / Metre);
qz.push_back(q.coordinates().z / Metre);
px.push_back(p.coordinates().x / (Metre / Second));
py.push_back(p.coordinates().y / (Metre / Second));
pz.push_back(p.coordinates().z / (Metre / Second));
if (previous_instant.has_value()) {
max_Δt = std::max(max_Δt, time - *previous_instant);
}
previous_instant = time;
}
previous_instant = instant;
}
zfp->set_timeline_size(timeline_size);

// Times are exact.
ZfpCompressor time_compressor(0);
@@ -644,7 +663,7 @@ bool DiscreteTrajectory<Frame>::WriteSubTreeToMessage(
speed_compressor.WriteToMessageMultidimensional<2>(pz, zfp_timeline);

if (downsampling_.has_value()) {
downsampling_->WriteToMessage(message->mutable_downsampling());
downsampling_->WriteToMessage(after_time, message->mutable_downsampling());
}
return true;
}
Loading