First, look at the typical ball-point pen style that includes a "click" mechanism to extend or retract the nib. We build a lot of similar mechanisms into the floor at various locations (each maybe 1 cm square), such that at any one of them, when "up" the floor is nice and even, and when "down", a small
square of floor is depressed below the main floor level. (We don't want this to be done TOO easily; the spring inside the mechanism needs some stiffness.) Inside the revealed hole will be a side-notch.
In the above sketch, one or more side notches would be located in the vertical space between the depressed area and the upper main floor level.
The Carpet or Rug needs to be a bit special, so that it has "hooks" that can fit into multiple notches in the floor. We would like to stretch the carpet/rug just a little, so it doesn't move around after being hooked into place. The hooks themselves might be removable, much like curtain hooks.
When we want to remove (or simply move) the carpet/rug, just unhook it and then use the click-mechanisms to raise the small depressed floor areas back to normal level.