Returns an input shard state for the remaining inputs.

    Returns:
      A json-izable version of the remaining InputReader.
973018
def to_json(self):
    
    result = super(_ReducerReader, self).to_json()
    result["current_key"] = self.encode_data(self.current_key)
    result["current_values"] = self.encode_data(self.current_values)
    return result
1328063
def unpack_shards(shards, stream_arn, session):
    
    if not shards:
        return {}

    # When unpacking tokens, shard id key is "shard_id"
    # When unpacking DescribeStream responses, shard id key is "ShardId"
    if "ShardId" in shards[0]:
        shards = _translate_shards(shards)

    by_id = {shard_token["shard_id"]:
             Shard(stream_arn=stream_arn, shard_id=shard_token["shard_id"],
                   iterator_type=shard_token.get("iterator_type"), sequence_number=shard_token.get("sequence_number"),
                   parent=shard_token.get("parent"), session=session)
             for shard_token in shards}

    for shard in by_id.values():
        if shard.parent:
            shard.parent = by_id[shard.parent]
            shard.parent.children.append(shard)
    return by_id
1000824
def spent_outputs(self):
        
        return (
            input_.fulfills.to_dict()
            for input_ in self.inputs if input_.fulfills
        )
290233
def get_client(self, shard_key):
        
        self._prune_penalty_box()

        if len(self.active_clients) == 0:
            raise ClusterEmptyError("All clients are down.")

        # So that hashing is consistent when a node is down, check against
        # the initial client list. Only use the active client list when
        # the desired node is down.
        # N.B.: I know this is not technically "consistent hashing" as
        #       academically defined. It's a hack so that keys which need to
        #       go elsewhere do, while the rest stay on the same instance.
        if not isinstance(shard_key, bytes):
            shard_key = shard_key.encode("utf-8")
        hashed = mmh3.hash(shard_key)
        pos = hashed % len(self.initial_clients)
        if self.initial_clients[pos] in self.active_clients:
            return self.initial_clients[pos]
        else:
            pos = hashed % len(self.active_clients)
            return self.active_clients[pos]
658931
def _compute(self, feed_dict, shard):
        

        try:
            descriptor, enq = self._tfrun(self._tf_expr[shard], feed_dict=feed_dict)
            self._inputs_waiting.decrement(shard)

        except Exception as e:
            montblanc.log.exception("Compute Exception")
            raise
976132
def get_state():
    
    sdp_state = SDPState()
    errval, errdict = _check_status(sdp_state)
    if errval == "error":
        LOG.debug(errdict['reason'])
        return dict(
            current_state="unknown",
            target_state="unknown",
            last_updated="unknown",
            reason=errdict['reason']
        )
    _last_updated = sdp_state.current_timestamp
    if sdp_state.target_timestamp > _last_updated:
        _last_updated = sdp_state.target_timestamp

    return dict(
        current_state=sdp_state.current_state,
        target_state=sdp_state.target_state,
        allowed_target_states=sdp_state.allowed_target_states[
            sdp_state.current_state],
        last_updated=_last_updated.isoformat()
    ), HTTPStatus.OK
1349488
def is_in_shard(self, s):
    
    return self.compute_shard(s, self._nshards) == self._shard
1264285
def state_dict(self) -> dict:
        
        hidden_state = {}

        if self.optimizer is not None:
            hidden_state['optimizer'] = self.optimizer.state_dict()

        for callback in self.callbacks:
            callback.write_state_dict(self.training_info, hidden_state)

        return hidden_state
817131
def column_headers_from_list_of_dicts(self, json_input):
        
        if not json_input \
        or not hasattr(json_input, '__getitem__') \
        or not hasattr(json_input[0], 'keys'):
            return None
        column_headers = json_input[0].keys()
        for entry in json_input:
            if not hasattr(entry, 'keys') \
            or not hasattr(entry, '__iter__') \
            or len(entry.keys()) != len(column_headers):
                return None
            for header in column_headers:
                if header not in entry:
                    return None
        return column_headers
339522
def get_shard_map(self, force_refresh=False):
        
        now = datetime.utcnow()
        if force_refresh is True or \
                        self.shard_map is None or \
                        (now - self.last_refresh).total_seconds() > self.refresh_ttl:
            self.last_refresh = now
            self.refresh_shard_map()
        return self.shard_map
1144384
def _w_between_shards(args: Dict[str, Any]):
    """"""
    shard_num = args['shard_num']
    state = _state_shard(args)
    num_shard_qubits = args['num_shard_qubits']
    index = args['index']
    half_turns = args['half_turns']

    axis_half_turns = args['axis_half_turns']

    perm_index = shard_num ^ (1 << (index - num_shard_qubits))
    perm_state = mem_manager.SharedMemManager.get_array(
        args['state_handle']).view(np.complex64)[perm_index]

    cos = np.cos(-0.5 * np.pi * half_turns)
    sin = np.sin(-0.5 * np.pi * half_turns)

    cos_axis = np.cos(np.pi * axis_half_turns)
    sin_axis = np.sin(np.pi * axis_half_turns)

    scratch = _scratch_shard(args)
    z_op = (1 - 2 * _kth_bit(shard_num, index - num_shard_qubits))
    np.copyto(scratch, state * cos + 1j * sin * perm_state *
              (cos_axis - 1j * sin_axis * z_op))
1180324
def get_key_state(self, status, state_dict):
        
        for key, val in state_dict.items():
            if val == status:
                return key
635376
def shard(items, num_shards):
  """"""
  sharded = []
  num_per_shard = len(items) // num_shards
  start = 0
  for _ in range(num_shards):
    sharded.append(items[start:start + num_per_shard])
    start += num_per_shard

  remainder = len(items) % num_shards
  start = len(items) - remainder
  for i in range(remainder):
    sharded[i].append(items[start + i])

  assert sum([len(fs) for fs in sharded]) == len(items)
  return sharded
307050
def _get_next_open_shard(stream_details, shard_id):
    '''
    
    '''
    found = False
    for shard in stream_details["OpenShards"]:
        current_shard_id = shard["ShardId"]
        if current_shard_id == shard_id:
            found = True
            continue
        if found:
            return current_shard_id
821369
@Override
  protected ShardsIterator shards(ClusterState clusterState, GetIndicesVersionRequest request, String[] concreteIndices) {
    return clusterState.routingTable().allShards(concreteIndices);
  }
1117795
def Deserialize(self, reader):
        
        super(SpentCoinState, self).Deserialize(reader)

        self.TransactionHash = reader.ReadUInt256()
        self.TransactionHeight = reader.ReadUInt32()

        count = reader.ReadVarInt()

        items = [0] * count
        for i in range(0, count):
            index = reader.ReadUInt16()
            height = reader.ReadUInt32()
            items[i] = SpentCoinItem(index=index, height=height)

        self.Items = items
1138778
def get_outputs(self):
    
    assert self.SUCCESS == self.get_status()
    ss = model.ShardState.find_all_by_mapreduce_state(self._state)
    for s in ss:
      yield iter(s.writer_state.get("outs", []))