qubiter.Controls module

class qubiter.Controls.Controls(num_bits)[source]

Bases: object

This class stores a dictionary called self.bit_pos_to_kind containing key-value pairs of the form (a control’s qubit number: its kind). Kinds can be either a bool or a non-negative integer. Kind is True if control is P_1 = n = |1><1|. Kind is False if control is P_0 = nbar = |0><0|. Kind is a non-negative integer for MP_Y and DIAG controls.

Variables:
  • bit_pos (list[int]) – This is the key’s half if you unzip bit_pos_to_kind, in decreasing order
  • bit_pos_to_kind (dict[int, bool|int]) – Dictionary matching control bit position with its kind. The domain of the map bit_pos_to_kind is a subset of range(num_bits)
  • kinds (list[bool|int]) – this is the value’s half if you unzip bit_pos_to_kind.
  • num_bits (int) – number of qubits in full quantum circuit
__init__(num_bits)[source]

Constructor

Parameters:num_bits (int) –
static copy(old, extra_bits=0)[source]

Create a copy of self but add extra_bit many uncontrolled bits at the end.

Parameters:
  • old (Controls) –
  • extra_bits (int) –
Returns:

Return type:

Controls

get_num_int_controls()[source]

Find number of controls that are not of boolean kind.

Returns:
Return type:int
get_workspace_bit_pot(target_bit_pos)[source]

Find a bit that is neither the target bit nor one of the controls. Make it as big as possible.

Parameters:target_bit_pos (int) –
Returns:
Return type:int
is_control(bit_pos)[source]

True if bit_pos in the keys of bit_pos_to_kind. False otherwise.

Parameters:bit_pos (int) –
Returns:
Return type:bool
new_embedded_self(emb)[source]

In bit_pos_to_kind, replace each key by a new key emb.bit_map[key]. Also add extra controls carried by emb.

Parameters:emb (CktEmbedder) –
Returns:
Return type:Controls
static new_knob(num_bits, bit_pos, kind)[source]

Returns a single control

Parameters:
  • num_bits (int) –
  • bit_pos (int) –
  • kind (bool|int) –
Returns:

Return type:

Controls

refresh_lists()[source]

Replace the 2 lists bit_pos and kinds by unzipping (actually zip() does both zip and unzip) the dictionary bit_pos_to_kind.

Returns:
Return type:None
set_control(bit_pos, kind, do_refresh=False)[source]

Add key-value pair (bit_pos: kind) to self.bit_pos_to_kind dictionary

Parameters:
  • bit_pos (int) –
  • kind (bool|int) –
  • do_refresh (bool) –
Returns:

Return type:

None