text:
"""The :mod:`zmq` module wraps the :class:`Socket` and :class:`Context`
found in :mod:`pyzmq <zmq>` to be non blocking
"""

from __future__ import with_statement

__zmq__ = __import__('zmq')
from eventlet import hubs
from eventlet.patcher import slurp_properties
from eventlet.support import greenlets as greenlet

__patched__ = ['Context', 'Socket']
slurp_properties(__zmq__, globals(), ignore=__patched__)

from collections import deque

try:
    # alias XREQ/XREP to DEALER/ROUTER if available
    if not hasattr(__zmq__, 'XREQ'):
        XREQ = DEALER
    if not hasattr(__zmq__, 'XREP'):
        XREP = ROUTER
except NameError:
    pass

class LockReleaseError(Exception):
    pass

class _QueueLock(object):
    """A Lock that can be acquired by at most one thread. Any other
    thread calling acquire will be blocked in a queue. When release
    is called, the threads are awoken in the order they blocked,
    one at a time. This lock can be required recursively by the same
    thread."""

    def __init__(self):
        self._waiters = deque()
        self._count = 0
        self._holder = None
        self._hub = hubs.get_hub()

    def __nonzero__(self):
        return bool(self._count)

    __bool__ = __nonzero__

    def __enter__(self):
        self.acquire()

    def __exit__(self, type, value, traceback):
        self.release()

    def acquire(self):
        current = greenlet.getcurrent()
        if (self._waiters or self._count > 0) and self._holder is not current:
            # block until lock is free
            self._waiters.append(current)
            self._hub.switch()
            w = self._waiters.popleft()

            assert w is current, 'Waiting threads woken out of order'
            assert self._count == 0, 'After waking a thread, the lock must be unacquired'

        self._holder = current
        self._count += 1

    def release(self):
        if self._count <= 0:
            raise LockReleaseError("Cannot release unacquired lock")

        self._count -= 1
        if self._count == 0:
            self._holder = None
            if self._waiters:
                # wake next
                self._hub.schedule_call_global(0, self._waiters[0].switch)

class _BlockedThread(object):
    """Is either empty, or represents a single blocked thread that
    blocked itself by calling the block() method. The thread can be
    awoken by calling wake(). Wake() can be called multiple times and
    all but the first call will have no effect."""

    def __init__(self):
        self._blocked_thread = None
        self._wakeupper = None
        self._hub = hubs.get_hub()

    def __nonzero__(self):
        return self._blocked_thread is not None

    __bool__ = __nonzero__

    def block(self):
        if self._blocked_thread is not None:
            raise Exception("Cannot block more than one thread on one BlockedThread")
        self._blocked_thread = greenlet.getcurrent()

        try:
            self._hub.switch()
        finally:
            self._blocked_thread = None
            # cleanup the wakeup task
            if self._wakeupper is not None:
                # Important to cancel the wakeup task so it doesn't
                # spuriously wake this greenthread later on.
                self._wakeupper.cancel()
                self._wakeupper = None

    def wake(self):
        """Schedules the blocked thread to be awoken and return
        True. If wake has already been called or if there is no
        blocked thread, then this call has no effect and returns
        False."""
        if self._blocked_thread is not None and self._wakeupper is None:
            self._wakeupper = self._hub.schedule_call_global(0, self._blocked_thread.switch)
            return True
        return False

class Context(__zmq__.Context):
    """Subclass of :class:`zmq.core.context.Context`
    """

    def socket(self, socket_type):
        """Overridden method to ensure that the green version of socket is used

        Behaves the same as :meth:`zmq.core.context.Context.socket`, but ensures
        that a :class:`Socket` with all of its send and recv methods set to be
        non-blocking is returned
        """
        if self.closed:
            raise ZMQError(ENOTSUP)
        return Socket(self, socket_type)

def _wraps(source_fn):
    """A decorator that copies the __name__ and __doc__ from the given
    function
    """
    def wrapper(dest_fn):
        dest_fn.__name__ = source_fn.__name__
        dest_fn.__doc__ = source_fn.__doc__
        return dest_fn
    return wrapper

# Implementation notes: Each socket in 0mq contains a pipe that the
# background IO threads use to communicate with the socket. These
# events are important because they tell the socket when it is able to
# send and when it has messages waiting to be received. The read end
# of the events pipe is the same FD that getsockopt(zmq.FD) returns.
#
# Events are read from the socket's event pipe only on the thread that
# the 0mq context is associated with, which is the native thread the
# greenthreads are running on, and the only operations that cause the
# events to be read and processed are send(), recv() and
# getsockopt(zmq.EVENTS). This means that after doing any of these
# three operations, the ability of the socket to send or receive a
# message without blocking may have changed, but after the events are
# read the FD is no longer readable so the hub may not signal our
# listener.
#
# If we understand that after calling send() a message might be ready
# to be received and that after calling recv() a message might be able
# to be sent, what should we do next? There are two approaches:
#
#  1. Always wake the other thread if there is one waiting. This
#  wakeup may be spurious because the socket might not actually be
#  ready for a send() or recv().  However, if a thread is in a
#  tight-loop successfully calling send() or recv() then the wakeups
#  are naturally batched and there's very little cost added to each
#  send/recv call.
#
# or
#
#  2. Call getsockopt(zmq.EVENTS) and explicitly check if the other
#  thread should be woken up. This avoids spurious wake-ups but may
#  add overhead because getsockopt will cause all events to be
#  processed, whereas send and recv throttle processing
#  events. Admittedly, all of the events will need to be processed
#  eventually, but it is likely faster to batch the processing.
#
# Which approach is better? I have no idea.
#
# TODO:
# - Support MessageTrackers and make MessageTracker.wait green

_Socket = __zmq__.Socket
_Socket_recv = _Socket.recv
_Socket_send = _Socket.send
_Socket_send_multipart = _Socket.send_multipart
_Socket_recv_multipart = _Socket.recv_multipart
_Socket_getsockopt = _Socket.getsockopt

class Socket(_Socket):
    """Green version of :class:`zmq.core.socket.Socket

    The following three methods are always overridden:
        * send
        * recv
        * getsockopt
    To ensure that the ``zmq.NOBLOCK`` flag is set and that sending or receiving
    is deferred to the hub (using :func:`eventlet.hubs.trampoline`) if a
    ``zmq.EAGAIN`` (retry) error is raised

    For some socket types, the following methods are also overridden:
        * send_multipart
        * recv_multipart
    """

    def __init__(self, context, socket_type):
        super(Socket, self).__init__(context, socket_type)

        self.__dict__['_eventlet_send_event'] = _BlockedThread()
        self.__dict__['_eventlet_recv_event'] = _BlockedThread()
        self.__dict__['_eventlet_send_lock'] = _QueueLock()
        self.__dict__['_eventlet_recv_lock'] = _QueueLock()

        def event(fd):
            # Some events arrived at the zmq socket. This may mean
            # there's a message that can be read or there's space for
            # a message to be written.
            send_wake = self._eventlet_send_event.wake()
            recv_wake = self._eventlet_recv_event.wake()
            if not send_wake and not recv_wake:
                # if no waiting send or recv thread was woken up, then
                # force the zmq socket's events to be processed to
                # avoid repeated wakeups
                _Socket_getsockopt(self, EVENTS)

        hub = hubs.get_hub()
        self.__dict__['_eventlet_listener'] = hub.add(hub.READ,
                                                      self.getsockopt(FD),
                                                      event,
                                                      lambda _: None,
                                                      lambda: None)

    @_wraps(_Socket.close)
    def close(self, linger=None):
        super(Socket, self).close(linger)
        if self._eventlet_listener is not None:
            hubs.get_hub().remove(self._eventlet_listener)
            self.__dict__['_eventlet_listener'] = None
            # wake any blocked threads
            self._eventlet_send_event.wake()
            self._eventlet_recv_event.wake()

    @_wraps(_Socket.getsockopt)
    def getsockopt(self, option):
        result = _Socket_getsockopt(self, option)
        if option == EVENTS:
            # Getting the events causes the zmq socket to process
            # events which may mean a msg can be sent or received. If
            # there is a greenthread blocked and waiting for events,
            # it will miss the edge-triggered read event, so wake it
            # up.
            if (result & POLLOUT):
                self._eventlet_send_event.wake()
            if (result & POLLIN):
                self._eventlet_recv_event.wake()
        return result

    @_wraps(_Socket.send)
    def send(self, msg, flags=0, copy=True, track=False):
        """A send method that's safe to use when multiple greenthreads
        are calling send, send_multipart, recv and recv_multipart on
        the same socket.
        """
        if flags & NOBLOCK:
            result = _Socket_send(self, msg, flags, copy, track)
            # Instead of calling both wake methods, could call
            # self.getsockopt(EVENTS) which would trigger wakeups if
            # needed.
            self._eventlet_send_event.wake()
            self._eventlet_recv_event.wake()
            return result

        # TODO: pyzmq will copy the message buffer and create Message
        # objects under some circumstances. We could do that work here
        # once to avoid doing it every time the send is retried.
        flags |= NOBLOCK
        with self._eventlet_send_lock:
            while True:
                try:
                    return _Socket_send(self, msg, flags, copy, track)
                except ZMQError as e:
                    if e.errno == EAGAIN:
                        self._eventlet_send_event.block()
                    else:
                        raise
                finally:
                    # The call to send processes 0mq events and may
                    # make the socket ready to recv. Wake the next
                    # receiver. (Could check EVENTS for POLLIN here)
                    self._eventlet_recv_event.wake()

    @_wraps(_Socket.send_multipart)
    def send_multipart(self, msg_parts, flags=0, copy=True, track=False):
        """A send_multipart method that's safe to use when multiple
        greenthreads are calling send, send_multipart, recv and
        recv_multipart on the same socket.
        """
        if flags & NOBLOCK:
            return _Socket_send_multipart(self, msg_parts, flags, copy, track)

        # acquire lock here so the subsequent calls to send for the
        # message parts after the first don't block
        with self._eventlet_send_lock:
            return _Socket_send_multipart(self, msg_parts, flags, copy, track)

    @_wraps(_Socket.recv)
    def recv(self, flags=0, copy=True, track=False):
        """A recv method that's safe to use when multiple greenthreads
        are calling send, send_multipart, recv and recv_multipart on
        the same socket.
        """
        if flags & NOBLOCK:
            msg = _Socket_recv(self, flags, copy, track)
            # Instead of calling both wake methods, could call
            # self.getsockopt(EVENTS) which would trigger wakeups if
            # needed.
            self._eventlet_send_event.wake()
            self._eventlet_recv_event.wake()
            return msg

        flags |= NOBLOCK
        with self._eventlet_recv_lock:
            while True:
                try:
                    return _Socket_recv(self, flags, copy, track)
                except ZMQError as e:
                    if e.errno == EAGAIN:
                        self._eventlet_recv_event.block()
                    else:
                        raise
                finally:
                    # The call to recv processes 0mq events and may
                    # make the socket ready to send. Wake the next
                    # receiver. (Could check EVENTS for POLLOUT here)
                    self._eventlet_send_event.wake()

    @_wraps(_Socket.recv_multipart)
    def recv_multipart(self, flags=0, copy=True, track=False):
        """A recv_multipart method that's safe to use when multiple
        greenthreads are calling send, send_multipart, recv and
        recv_multipart on the same socket.
        """
        if flags & NOBLOCK:
            return _Socket_recv_multipart(self, flags, copy, track)

        # acquire lock here so the subsequent calls to recv for the
        # message parts after the first don't block
        with self._eventlet_recv_lock:
            return _Socket_recv_multipart(self, flags, copy, track)


text:
[![Container Logo](https://github.com/Adron/systemic-dockzoo/blob/master/Logo.png?raw=true)](https://github.com/Adron/systemic-dockzoo)

[![License](https://img.shields.io/github/license/Adron/systemic-dockzoo.svg?style=flat-square)](https://github.com/Adron/systemic-dockzoo/blob/master/LICENSE)
[![Maintenance](https://img.shields.io/maintenance/yes/2016.svg?style=flat-square)](#)
[![Issues](https://img.shields.io/github/issues/adron/systemic-dockzoo.svg?style=flat-square)](https://github.com/Adron/systemic-dockzoo/issues)
[![Docker Pulls](https://img.shields.io/docker/pulls/adron/systemic-dockzoo.svg?style=flat-square)](https://hub.docker.com/r/adron/dockzoo/)
[![ImageLayers Size](https://img.shields.io/imagelayers/image-size/_/adron/systemic-dockzoo.svg?style=flat-square)](https://hub.docker.com/r/adron/dockzoo/)
[![ImageLayers Layers](https://img.shields.io/imagelayers/layers/_/adron/systemic-dockzoo.svg?style=flat-square)](https://hub.docker.com/r/adron/dockzoo/)

The docker built images for Zookeeper tests & builds.

Create the image from this repository with:

    docker build .

Otherwise pull the docker image itself from Docker Hub:

    docker pull adron/systemic-dockzoo

To create and start a container from this image

    docker run -p 8181:8181 -p 2181:2181 -p 2888:2888 -p 3888:3888 adron/systemic-dockzoo

...or start with other services configured. This includes S3 bucket for backups, and the respective access key ID and secret access key. The hostname is the name of the associated host you might use with this particular cluster.

    docker run -p 8181:8181 -p 2181:2181 -p 2888:2888 -p 3888:3888 \
    -e BUCKET=<bucket> \
    -e PREFIX=<key_prefix> \
    -e ACCESS_KEY_ID=<access_key> \
    -e SECRET_ACCESS_KEY=<secret_key> \
    -e HOSTNAME=<host> \
    adron/systemic-dockzoo

## Verification of Services & User Interface

To verify that exhibitor has started and is available, navigate to:

    http://<hostname>:8181

For more information on Exhibitor check out the API https://github.com/Netflix/exhibitor/wiki/REST-Introduction.

To check that Zookeeper is a keepin'.

    echo ruok | nc <hostname> 2181

*Author(s):* [![Adron Hall](https://github.com/Adron/systemic-dockzoo/blob/master/AdronHall.png?raw=true)](http://compositecode.com) @ **[Github](https://www.github.com/adron)** or **[Twitter](https://twitter.com/adron)**.

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="ivy-report.xsl"?>
<ivy-report version="1.0">
	<info
		organisation="default"
		module="acciodb_2.10"
		revision="1.0.0"
		conf="pom"
		confs="compile, runtime, test, provided, optional, compile-internal, runtime-internal, test-internal, plugin, sources, docs, pom, scala-tool"
		date="20150919164957"/>
	<dependencies>
	</dependencies>
</ivy-report>


text:
This example illustrates how to connect to an LDAP directory in Mule and retrieve a list of users that is stored in that directory.

### LDAP

The Lightweight Directory Access Protocol (LDAP) is a public standard that facilitates distributed directories (such as network user privilege information) over the Internet Protocol (IP). The many available LDAP servers include free-use open source projects.

### Assumption

This document describes the details of the example within the context of **Anypoint™ Studio**, Mule ESB's graphical user interface (GUI). Where appropriate, the XML configuration is provided.

This document assumes that you are familiar with Mule ESB and the [Anypoint Studio interface](http://www.mulesoft.org/documentation/display/current/Anypoint+Studio+Essentials). To increase your familiarity with Mule Studio, consider completing one or more [Anypoint Studio Tutorials](http://www.mulesoft.org/documentation/display/current/Basic+Studio+Tutorial). Further, this example assumes that you have a basic understanding of [Mule flows](http://www.mulesoft.org/documentation/display/current/Mule+Application+Architecture) and [Mule Global Elements](http://www.mulesoft.org/documentation/display/current/Global+Elements).

### Example Use Case

The example application connects to an LDAP directory and retrieves a list of LDAP users.

### Set Up and Run the Example

1. Set up LDAP on your machine
   * For Windows: Install OpenLDAP from [http://www.openldap.org](http://www.openldap.org/).
   * For MacOS: OpenLDAP comes bundled with MacOS, so you do not need to download an LDAP server.

1. Install Apache Directory Studio from [http://directory.apache.org/studio/downloads.html](http://directory.apache.org/studio/downloads.html).

1. Navigate to `etc\openldap\slapd.conf` in your OpenLDAP installation directory and set `rootpw` in the **BDB database definitions** section to `root`. You might also need to encrypt the password by using the following command before adding it to the `slapd.conf` file:

		slappasswd -h {SHA} -s <password>

1. Start the LDAP server
   * For Windows: Enter `libexec\StartLDAP.cmd` at a command line.
   * For MacOS: Enter `sudo /usr/libexec/slapd -d 255`.

1. Start Apache Directory Studio and create a new connection by selecting **File > New ... > LDAP Connection**. Use these settings:

		name		local LDAP
		hostname	localhost
		port		389

1. Click **Check network parameter**. If the test is not succesful, your LDAP server is not running. If the test is successfule, click **Next**.

1. Set **Bind dn or user** to `cn=Manager,dc=my-domain,dc=com` and **Bind password** to `root`. Click **Check Authentication** to verify the connection. Click **Finish**.

1. Click **File > Import... > LDIF into LDAP** and then click **Next**.

1. Set the path to `ldap.ldif`, which is located in the `scr/main/resources` directory of this project. Set **Import into** to `local LDAP`. Click **Finish** to finish the import process. If you click **ROOT DSE** in the panel **LDAP browser**, you should see the imported data structure.

1. Open the Example project in Anypoint Studio from [Anypoint Exchange](http://www.mulesoft.org/documentation/display/current/Anypoint+Exchange).

1. In your application in Studio, click the **Global Elements** tab. Double-click the HTTP Listener global element to open its **Global Element Properties** panel. Change the contents of the **port** field to required HTTP port (e.g., 8081).

1. Double-click `ldap.xml` under `src/main/app directory` and click the **Global Elements** tab. Open **LDAP configuration** and specify these values:

		Principal DN	cn=Manager,dc=my-domain,dc=com
		Password		root
		URL 			ldap://localhost:389/dc=my-domain,dc=com

1. Run the Mule Application.

1. Open your browser and type `http://localhost:8081/` in the address bar.

You should see three user records in response:
```
[
    {
        "dn": "cn=admin,ou=people",
        "sn": "admin",
        "cn": "admin",
        "objectclass": [
            "top",
            "person"
        ],
        "userpassword": "mmcadmin"
    },
    {
        "dn": "cn=testuser1,ou=people",
        "sn": "testuser1",
        "cn": "testuser1",
        "objectclass": [
            "top",
            "person"
        ],
        "userpassword": "testuser1123"
    },
    {
        "dn": "cn=mmc,ou=people",
        "sn": "mmc",
        "cn": "mmc",
        "objectclass": [
            "top",
            "person"
        ],
        "userpassword": "mmc123"
    }
]
```
### How it Works

An [HTTP endpoint](http://www.mulesoft.org/documentation/display/current/HTTP+Connector) is responsible for listening to incoming HTTP requests and sending the response. The [LDAP Connector](http://www.mulesoft.org/connectors/ldap-connector) performs the search operation with the given search parameters.

The following steps outline the process to build this application:

1. Create a new Mule Project by going to **File > New... > Mule Project** and name it `Importing data from an LDAP Directory`.
2. Drag an **HTTP listener** into a new flow. This is an inbound endpoint for your proxy application and receives all the requests that reference its address.
3. Click on the plus sign next to the Connector Configuration field. A dialogue for creating HTTP Listener Configuration will be displayed. Specify these values:

		Host 	localhost
		Port 	8081
4. Click **Ok**.
5. Set the **Path** attribute to `/`.
6. Drag **Search operation of LDAP connector** into the flow. Add an LDAP Configuration. Configure it as follows:

		Principal DN	cn=Manager,dc=my-domain,dc=com
		Password		root
		Url 			ldap://localhost:389/dc=my-domain,dc=com

7. Test the connection to see if the connection parameters are correct.

8. Configure **Search operation**, added in the previous step, as follows:

		Base DN 	ou=people
		Filter 		(objectClass=*)

5. Build a JSON response using the **Set Payload** message processor.

Having completed the flow, you can hit the HTTP endpoint to see all the users stored in the LDAP system in the given domain.


text:
package org.jkiss.dbeaver.model.exec;

import org.jkiss.code.Nullable;

import java.util.List;

/**
 * Execution result.
 */
public interface DBCExecutionResult {

    @Nullable
    Throwable getError();

    @Nullable
    List<Throwable> getWarnings();

}


text:
{-
 - Capture.hs
 - By Steven Smith
 -}

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}

-- | 'Captureable' is a type class for types that can be parsed from 'Text'.
-- It is used by the 'capture' 'Route' to automatically handle parsing.
--
-- If you would like to make your own data type 'Captureable', then all that
-- needs to be implemented is 'captureParser', which is a 'Parser' from
-- <http://hackage.haskell.org/package/attoparsec attoparsec>. Do keep in mind
-- when writing 'Captureable' instances that the 'Text' input will be from a
-- @URI@ path segment, so not all possible characters will be available.
module Web.DumpTruck.Capture where

import Web.DumpTruck.Date

import Control.Applicative
import Data.Text (Text)
import Data.Text.Encoding
import Data.Attoparsec.Text
import Data.ByteString.Builder

import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS

-- | A type is 'Captureable' if a 'Parser' exists for it that can parse 'Text'
-- input coming from a @URI@ path segment.
--
-- Minimum definition: 'captureParser'
class Captureable a where
    -- | The @URI@ path segment 'Parser' for this data type
    captureParser :: Parser a
    -- | Performs the 'Text' parsing, which may fail.
    --
    -- Note: The default implementation should cover almost all use-cases for
    -- normal data types. This method exists solely for cases where parsing
    -- cannot fail, specifically for converting between various string types.
    performCapture :: Text -> Maybe a
    performCapture = either (const Nothing) Just . parseOnly captureParser

instance Captureable Text where
    captureParser = takeText
    performCapture = Just

instance Captureable LT.Text where
    captureParser = takeLazyText
    performCapture = Just . LT.fromStrict

instance Captureable BS.ByteString where
    captureParser = fmap encodeUtf8 takeText
    performCapture = Just . encodeUtf8

instance Captureable LBS.ByteString where
    captureParser = fmap (toLazyByteString . encodeUtf8Builder) takeText
    performCapture = Just . toLazyByteString . encodeUtf8Builder

instance Captureable Int where
    captureParser = decimal

instance Captureable Double where
    captureParser = double

instance Captureable Bool where
    captureParser = string "true" *> pure True <|> string "false" *> pure False

instance Captureable Char where
    captureParser = anyChar

-- String
instance Captureable [Char] where
    captureParser = fmap T.unpack takeText
    performCapture = Just . T.unpack

-- Note that stacking lists [[a]] is unlikely to do anything useful
instance Captureable a => Captureable [a] where
    captureParser = captureParser `sepBy1` (char ',')

instance Captureable GmtTime where
    captureParser = undefined -- TODO :(
    performCapture = parseGmtTime . encodeUtf8


text:
package com.gdn.venice.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import com.gdn.venice.persistence.VenParty;
import com.gdn.venice.persistence.VenPartyAddress;

/**
 *
 * @author yauritux
 *
 */
public interface VenPartyAddressDAO extends JpaRepository<VenPartyAddress, Long>{

	public List<VenPartyAddress> findByVenParty(VenParty venParty);
}


text:
<?php

namespace Predis\Command;

/**
 * @group commands
 * @group realm-list
 */
class ListPushHeadTest extends PredisCommandTestCase
{
    /**
     * {@inheritdoc}
     */
    protected function getExpectedCommand()
    {
        return 'Predis\Command\ListPushHead';
    }

    /**
     * {@inheritdoc}
     */
    protected function getExpectedId()
    {
        return 'LPUSH';
    }

    /**
     * @group disconnected
     */
    public function testFilterArguments()
    {
        $arguments = array('key', 'value1', 'value2', 'value3');
        $expected = array('key', 'value1', 'value2', 'value3');

        $command = $this->getCommand();
        $command->setArguments($arguments);

        $this->assertSame($expected, $command->getArguments());
    }

    /**
     * @group disconnected
     */
    public function testFilterArgumentsValuesAsSingleArray()
    {
        $arguments = array('key', array('value1', 'value2', 'value3'));
        $expected = array('key', 'value1', 'value2', 'value3');

        $command = $this->getCommand();
        $command->setArguments($arguments);

        $this->assertSame($expected, $command->getArguments());
    }

    /**
     * @group disconnected
     */
    public function testParseResponse()
    {
        $this->assertSame(1, $this->getCommand()->parseResponse(1));
    }

    /**
     * @group connected
     */
    public function testPushesElementsToHeadOfList()
    {
        $redis = $this->getClient();

        // NOTE: List push operations return the list length since Redis commit 520b5a3
        $this->assertSame(1, $redis->lpush('metavars', 'foo'));
        $this->assertSame(2, $redis->lpush('metavars', 'hoge'));
        $this->assertSame(array('hoge', 'foo'), $redis->lrange('metavars', 0, -1));
    }

    /**
     * @group connected
     * @expectedException \Predis\Response\ServerException
     * @expectedExceptionMessage Operation against a key holding the wrong kind of value
     */
    public function testThrowsExceptionOnWrongType()
    {
        $redis = $this->getClient();

        $redis->set('metavars', 'foo');
        $redis->lpush('metavars', 'hoge');
    }
}


text:
/* --------------------------------------------------------------

   reset.css
   * Resets default browser CSS.

-------------------------------------------------------------- */

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, code,
del, dfn, em, img, q, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
  margin: 0;
  padding: 0;
  border: 0;
  font-weight: inherit;
  font-style: inherit;
  font-size: 100%;
  font-family: inherit;
  vertical-align: baseline;
}

body {
  line-height: 1.5;
  margin: 0 1em;
}

/* Tables still need 'cellspacing="0"' in the markup. */
table { border-collapse: separate; border-spacing: 0; }
caption, th, td { text-align: left; font-weight: normal; }
table, td, th { vertical-align: middle; }

/* Remove possible quote marks (") from <q>, <blockquote>. */
blockquote:before, blockquote:after, q:before, q:after { content: ""; }
blockquote, q { quotes: "" ""; }

/* Remove annoying border on linked images. */
a img { border: none; }


text:
using System;
using System.Collections.Generic;
using System.Linq;

namespace Azure.ResourceManager.Insights.Models
{
    /// <summary> An Activity Log alert condition that is met when all its member conditions are met. </summary>
    public partial class ActivityLogAlertAllOfCondition
    {
        /// <summary> Initializes a new instance of ActivityLogAlertAllOfCondition. </summary>
        /// <param name="allOf"> The list of activity log alert conditions. </param>
        /// <exception cref="ArgumentNullException"> <paramref name="allOf"/> is null. </exception>
        public ActivityLogAlertAllOfCondition(IEnumerable<ActivityLogAlertLeafCondition> allOf)
        {
            if (allOf == null)
            {
                throw new ArgumentNullException(nameof(allOf));
            }

            AllOf = allOf.ToList();
        }

        /// <summary> Initializes a new instance of ActivityLogAlertAllOfCondition. </summary>
        /// <param name="allOf"> The list of activity log alert conditions. </param>
        internal ActivityLogAlertAllOfCondition(IList<ActivityLogAlertLeafCondition> allOf)
        {
            AllOf = allOf;
        }

        /// <summary> The list of activity log alert conditions. </summary>
        public IList<ActivityLogAlertLeafCondition> AllOf { get; }
    }
}


text:
module TZInfo
  module Data
    module Definitions
      module Australia
        module North
          include TimezoneDefinition

          linked_timezone 'Australia/North', 'Australia/Darwin'
        end
      end
    end
  end
end


text:
FOR_RELEASE = 1

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = FacesPro
FacesPro_FILES = Tweak.xm BRFPPreferencesManager.m UIImage+AverageColor.m
FacesPro_FRAMEWORKS = CoreGraphics Contacts AddressBookUI Cephei
FacesPro_EXTRA_FRAMEWORKS = Cephei
FacesPro_LIBRARIES = colorpicker

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
ifeq ($(RESPRING),0)
	install.exec "killall Preferences"
else
	install.exec spring
endif

SUBPROJECTS += prefs
include $(THEOS_MAKE_PATH)/aggregate.mk


text:
var net = require('net');
var replClient = net.connect({path: 'prepl.sock'}, function() {
    console.log('connected!');
});

replClient.on('data', function(data) {
    console.log(data.toString());
});

replClient.on('error', function (err) {
    console.log(err);
})

var commands = [
    'help\n',
    'kill\n',
    'status\n',
    'start\n',
    'status\n'
];

for (var i = 0; i < commands.length; i++) {
    (function (command) {
        setTimeout(function() {
            replClient.write(command);
        }, i*2000);
    }(commands[i]));
}


text:
package net.sourceforge.squirrel_sql.client.preferences;

import java.awt.Component;

import net.sourceforge.squirrel_sql.client.IApplication;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;

class ProxyPreferencesPanel implements IGlobalPreferencesPanel
{
	/** Internationalized strings for this class. */
	private static final StringManager s_stringMgr =
		StringManagerFactory.getStringManager(ProxyPreferencesPanel.class);

	/** Panel to be displayed in preferences dialog. */
	private ProxyPreferenceTabComponent _myPanel;

	/** Application API. */
	private IApplication _app;

	/**
	 * Default ctor.
	 */
	public ProxyPreferencesPanel()
	{
		super();
	}

	public void initialize(IApplication app)
	{
		if (app == null)
		{
			throw new IllegalArgumentException("Null IApplication passed");
		}

		_app = app;

		((ProxyPreferenceTabComponent)getPanelComponent()).loadData(_app, _app.getSquirrelPreferences());
	}

   public void uninitialize(IApplication app)
   {

   }

   public synchronized Component getPanelComponent()
	{
		if (_myPanel == null)
		{
			_myPanel = new ProxyPreferenceTabComponent();
		}
		return _myPanel;
	}

	public void applyChanges()
	{
		_myPanel.applyChanges(_app.getSquirrelPreferences());
	}

	public String getTitle()
	{
		return s_stringMgr.getString("ProxyPreferencesPanel.title");
	}

	public String getHint()
	{
		return s_stringMgr.getString("ProxyPreferencesPanel.hint");
	}

}


text:
from __future__ import division, print_function

import logging
import os

import candle
import numpy as np
import pandas as pd
import tensorflow as tf
import uno as benchmark
import uno_data
from scipy.stats.stats import pearsonr
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
from tensorflow import keras
from tensorflow.keras import backend as K
from tensorflow.keras import optimizers
from tensorflow.keras.callbacks import (
    Callback,
    LearningRateScheduler,
    ModelCheckpoint,
    ReduceLROnPlateau,
    TensorBoard,
)
from tensorflow.keras.layers import Dense, Dropout, Input
from tensorflow.keras.models import Model
from uno_data import CombinedDataGenerator, CombinedDataLoader, DataFeeder

logger = logging.getLogger(__name__)
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
tf.compat.v1.disable_eager_execution()

def extension_from_parameters(args):
    """Construct string for saving model with annotation of parameters"""
    ext = ""
    ext += ".A={}".format(args.activation)
    ext += ".B={}".format(args.batch_size)
    ext += ".E={}".format(args.epochs)
    ext += ".O={}".format(args.optimizer)
    # ext += '.LEN={}'.format(args.maxlen)
    ext += ".LR={}".format(args.learning_rate)
    ext += ".CF={}".format("".join([x[0] for x in sorted(args.cell_features)]))
    ext += ".DF={}".format("".join([x[0] for x in sorted(args.drug_features)]))
    if args.feature_subsample > 0:
        ext += ".FS={}".format(args.feature_subsample)
    if args.dropout > 0:
        ext += ".DR={}".format(args.dropout)
    if args.warmup_lr:
        ext += ".wu_lr"
    if args.reduce_lr:
        ext += ".re_lr"
    if args.residual:
        ext += ".res"
    if args.use_landmark_genes:
        ext += ".L1000"
    if args.no_gen:
        ext += ".ng"
    for i, n in enumerate(args.dense):
        if n > 0:
            ext += ".D{}={}".format(i + 1, n)
    if args.dense_feature_layers != args.dense:
        for i, n in enumerate(args.dense):
            if n > 0:
                ext += ".FD{}={}".format(i + 1, n)

    return ext

def evaluate_prediction(y_true, y_pred):
    mse = mean_squared_error(y_true, y_pred)
    mae = mean_absolute_error(y_true, y_pred)
    r2 = r2_score(y_true, y_pred)
    corr, _ = pearsonr(y_true, y_pred)
    return {"mse": mse, "mae": mae, "r2": r2, "corr": corr}

def log_evaluation(metric_outputs, logger, description="Comparing y_true and y_pred:"):
    logger.info(description)
    for metric, value in metric_outputs.items():
        logger.info("  {}: {:.4f}".format(metric, value))

class LoggingCallback(Callback):
    def __init__(self, print_fcn=print):
        Callback.__init__(self)
        self.print_fcn = print_fcn

    def on_epoch_end(self, epoch, logs={}):
        msg = "[Epoch: %i] %s" % (
            epoch,
            ", ".join("%s: %f" % (k, v) for k, v in sorted(logs.items())),
        )
        self.print_fcn(msg)

class PermanentDropout(Dropout):
    def __init__(self, rate, **kwargs):
        super(PermanentDropout, self).__init__(rate, **kwargs)
        self.uses_learning_phase = False

    def call(self, x, mask=None):
        if 0.0 < self.rate < 1.0:
            noise_shape = self._get_noise_shape(x)
            x = K.dropout(x, self.rate, noise_shape)
        return x

class MultiGPUCheckpoint(ModelCheckpoint):
    def set_model(self, model):
        if isinstance(model.layers[-2], Model):
            self.model = model.layers[-2]
        else:
            self.model = model

def build_feature_model(
    input_shape,
    name="",
    dense_layers=[1000, 1000],
    kernel_initializer="glorot_normal",
    activation="relu",
    residual=False,
    dropout_rate=0,
    permanent_dropout=True,
):
    x_input = Input(shape=input_shape)
    h = x_input
    for i, layer in enumerate(dense_layers):
        x = h
        h = Dense(layer, activation=activation, kernel_initializer=kernel_initializer)(
            h
        )
        if dropout_rate > 0:
            if permanent_dropout:
                h = PermanentDropout(dropout_rate)(h)
            else:
                h = Dropout(dropout_rate)(h)
        if residual:
            try:
                h = keras.layers.add([h, x])
            except ValueError:
                pass
    model = Model(x_input, h, name=name)
    return model

class SimpleWeightSaver(Callback):
    def __init__(self, fname):
        self.fname = fname

    def set_model(self, model):
        if isinstance(model.layers[-2], Model):
            self.model = model.layers[-2]
        else:
            self.model = model

    def on_train_end(self, logs={}):
        self.model.save_weights(self.fname)

def build_model(loader, args, permanent_dropout=True, silent=False):
    input_models = {}
    dropout_rate = args.dropout

    initializer = (
        "glorot_normal"
        if hasattr(args, "initialization") is False
        else args.initialization
    )
    kernel_initializer = candle.build_initializer(
        initializer, candle.keras_default_config(), args.rng_seed
    )

    for fea_type, shape in loader.feature_shapes.items():
        base_type = fea_type.split(".")[0]
        if base_type in ["cell", "drug"]:
            if args.dense_cell_feature_layers is not None and base_type == "cell":
                dense_feature_layers = args.dense_cell_feature_layers
            elif args.dense_drug_feature_layers is not None and base_type == "drug":
                dense_feature_layers = args.dense_drug_feature_layers
            else:
                dense_feature_layers = args.dense_feature_layers

            box = build_feature_model(
                input_shape=shape,
                name=fea_type,
                dense_layers=dense_feature_layers,
                kernel_initializer=kernel_initializer,
                dropout_rate=dropout_rate,
                permanent_dropout=permanent_dropout,
            )
            if not silent:
                logger.debug("Feature encoding submodel for %s:", fea_type)
                box.summary(print_fn=logger.debug)
            input_models[fea_type] = box

    inputs = []
    encoded_inputs = []
    for fea_name, fea_type in loader.input_features.items():
        shape = loader.feature_shapes[fea_type]
        fea_input = Input(shape, name="input." + fea_name)
        inputs.append(fea_input)
        if fea_type in input_models:
            input_model = input_models[fea_type]
            encoded = input_model(fea_input)
        else:
            encoded = fea_input
        encoded_inputs.append(encoded)

    merged = keras.layers.concatenate(encoded_inputs)

    h = merged
    for i, layer in enumerate(args.dense):
        x = h
        h = Dense(
            layer, activation=args.activation, kernel_initializer=kernel_initializer
        )(h)
        if dropout_rate > 0:
            if permanent_dropout:
                h = PermanentDropout(dropout_rate)(h)
            else:
                h = Dropout(dropout_rate)(h)
        if args.residual:
            try:
                h = keras.layers.add([h, x])
            except ValueError:
                pass
    output = Dense(1, kernel_initializer=kernel_initializer)(h)

    return Model(inputs, output)

def initialize_parameters(default_model="uno_default_model.txt"):

    # Build benchmark object
    unoBmk = benchmark.BenchmarkUno(
        benchmark.file_path,
        default_model,
        "keras",
        prog="uno_baseline",
        desc="Build neural network based models to predict tumor response to single and paired drugs.",
    )

    # Initialize parameters
    gParameters = candle.finalize_parameters(unoBmk)
    # benchmark.logger.info('Params: {}'.format(gParameters))

    return gParameters

def run(params):
    args = candle.ArgumentStruct(**params)
    candle.set_seed(args.rng_seed)
    ext = extension_from_parameters(args)
    candle.verify_path(args.save_path)
    prefix = args.save_path + ext
    logfile = args.logfile if args.logfile else prefix + ".log"
    candle.set_up_logger(logfile, logger, args.verbose)
    logger.info("Params: {}".format(params))

    if len(args.gpus) > 0:
        import tensorflow as tf

        config = tf.compat.v1.ConfigProto()
        config.gpu_options.allow_growth = True
        config.gpu_options.visible_device_list = ",".join(map(str, args.gpus))
        tf.compat.v1.keras.backend.set_session(tf.compat.v1.Session(config=config))

    loader = CombinedDataLoader(seed=args.rng_seed)
    loader.load(
        cache=args.cache,
        ncols=args.feature_subsample,
        agg_dose=args.agg_dose,
        cell_features=args.cell_features,
        drug_features=args.drug_features,
        drug_median_response_min=args.drug_median_response_min,
        drug_median_response_max=args.drug_median_response_max,
        use_landmark_genes=args.use_landmark_genes,
        use_filtered_genes=args.use_filtered_genes,
        cell_feature_subset_path=args.cell_feature_subset_path
        or args.feature_subset_path,
        drug_feature_subset_path=args.drug_feature_subset_path
        or args.feature_subset_path,
        preprocess_rnaseq=args.preprocess_rnaseq,
        single=args.single,
        train_sources=args.train_sources,
        test_sources=args.test_sources,
        embed_feature_source=not args.no_feature_source,
        encode_response_source=not args.no_response_source,
        use_exported_data=args.use_exported_data,
    )

    target = args.agg_dose or "Growth"
    val_split = args.val_split
    train_split = 1 - val_split

    if args.export_csv:
        fname = args.export_csv
        loader.partition_data(
            cv_folds=args.cv,
            train_split=train_split,
            val_split=val_split,
            cell_types=args.cell_types,
            by_cell=args.by_cell,
            by_drug=args.by_drug,
            cell_subset_path=args.cell_subset_path,
            drug_subset_path=args.drug_subset_path,
        )
        train_gen = CombinedDataGenerator(
            loader, batch_size=args.batch_size, shuffle=args.shuffle
        )
        val_gen = CombinedDataGenerator(
            loader, partition="val", batch_size=args.batch_size, shuffle=args.shuffle
        )

        x_train_list, y_train = train_gen.get_slice(
            size=train_gen.size, dataframe=True, single=args.single
        )
        x_val_list, y_val = val_gen.get_slice(
            size=val_gen.size, dataframe=True, single=args.single
        )
        df_train = pd.concat([y_train] + x_train_list, axis=1)
        df_val = pd.concat([y_val] + x_val_list, axis=1)
        df = pd.concat([df_train, df_val]).reset_index(drop=True)
        if args.growth_bins > 1:
            df = uno_data.discretize(df, "Growth", bins=args.growth_bins)
        df.to_csv(fname, sep="\t", index=False, float_format="%.3g")
        return

    if args.export_data:
        fname = args.export_data
        loader.partition_data(
            cv_folds=args.cv,
            train_split=train_split,
            val_split=val_split,
            cell_types=args.cell_types,
            by_cell=args.by_cell,
            by_drug=args.by_drug,
            cell_subset_path=args.cell_subset_path,
            drug_subset_path=args.drug_subset_path,
        )
        train_gen = CombinedDataGenerator(
            loader, batch_size=args.batch_size, shuffle=args.shuffle
        )
        val_gen = CombinedDataGenerator(
            loader, partition="val", batch_size=args.batch_size, shuffle=args.shuffle
        )
        store = pd.HDFStore(fname)

        config_min_itemsize = {"Sample": 30, "Drug1": 10}
        if not args.single:
            config_min_itemsize["Drug2"] = 10

        for partition in ["train", "val"]:
            gen = train_gen if partition == "train" else val_gen
            for i in range(gen.steps):
                x_list, y = gen.get_slice(
                    size=args.batch_size, dataframe=True, single=args.single
                )

                for j, input_feature in enumerate(x_list):
                    input_feature.columns = [""] * len(input_feature.columns)
                    store.append(
                        "x_{}_{}".format(partition, j),
                        input_feature.astype("float32"),
                        format="table",
                    )
                store.append(
                    "y_{}".format(partition),
                    y.astype({target: "float32"}),
                    format="table",
                    min_itemsize=config_min_itemsize,
                )
                logger.info(
                    "Generating {} dataset. {} / {}".format(partition, i, gen.steps)
                )

        # save input_features and feature_shapes from loader
        store.put("model", pd.DataFrame())
        store.get_storer("model").attrs.input_features = loader.input_features
        store.get_storer("model").attrs.feature_shapes = loader.feature_shapes

        store.close()
        logger.info("Completed generating {}".format(fname))
        return

    if args.use_exported_data is None:
        loader.partition_data(
            cv_folds=args.cv,
            train_split=train_split,
            val_split=val_split,
            cell_types=args.cell_types,
            by_cell=args.by_cell,
            by_drug=args.by_drug,
            cell_subset_path=args.cell_subset_path,
            drug_subset_path=args.drug_subset_path,
        )

    model = build_model(loader, args)
    logger.info("Combined model:")
    model.summary(print_fn=logger.info)
    # plot_model(model, to_file=prefix+'.model.png', show_shapes=True)

    if args.cp:
        model_json = model.to_json()
        with open(prefix + ".model.json", "w") as f:
            print(model_json, file=f)

    def warmup_scheduler(epoch):
        lr = args.learning_rate or base_lr * args.batch_size / 100
        if epoch <= 5:
            K.set_value(model.optimizer.lr, (base_lr * (5 - epoch) + lr * epoch) / 5)
        logger.debug(
            "Epoch {}: lr={:.5g}".format(epoch, K.get_value(model.optimizer.lr))
        )
        return K.get_value(model.optimizer.lr)

    df_pred_list = []

    cv_ext = ""
    cv = args.cv if args.cv > 1 else 1

    for fold in range(cv):
        if args.cv > 1:
            logger.info("Cross validation fold {}/{}:".format(fold + 1, cv))
            cv_ext = ".cv{}".format(fold + 1)

        template_model = build_model(loader, args, silent=True)
        if args.initial_weights:
            logger.info("Loading initial weights from {}".format(args.initial_weights))
            template_model.load_weights(args.initial_weights)

        if len(args.gpus) > 1:
            from tensorflow.keras.utils import multi_gpu_model

            gpu_count = len(args.gpus)
            logger.info("Multi GPU with {} gpus".format(gpu_count))
            model = multi_gpu_model(template_model, cpu_merge=False, gpus=gpu_count)
        else:
            model = template_model

        optimizer = optimizers.deserialize({"class_name": args.optimizer, "config": {}})
        base_lr = args.base_lr or K.get_value(optimizer.lr)
        if args.learning_rate:
            K.set_value(optimizer.lr, args.learning_rate)

        model.compile(
            loss=args.loss, optimizer=optimizer, metrics=[candle.mae, candle.r2]
        )

        # calculate trainable and non-trainable params
        params.update(candle.compute_trainable_params(model))

        candle_monitor = candle.CandleRemoteMonitor(params=params)
        timeout_monitor = candle.TerminateOnTimeOut(params["timeout"])
        es_monitor = keras.callbacks.EarlyStopping(patience=10, verbose=1)

        reduce_lr = ReduceLROnPlateau(
            monitor="val_loss", factor=0.5, patience=5, min_lr=0.00001
        )
        warmup_lr = LearningRateScheduler(warmup_scheduler)
        checkpointer = MultiGPUCheckpoint(
            prefix + cv_ext + ".model.h5", save_best_only=True
        )
        tensorboard = TensorBoard(
            log_dir="tb/{}{}{}".format(args.tb_prefix, ext, cv_ext)
        )
        history_logger = LoggingCallback(logger.debug)

        callbacks = [candle_monitor, timeout_monitor, history_logger]
        if args.es:
            callbacks.append(es_monitor)
        if args.reduce_lr:
            callbacks.append(reduce_lr)
        if args.warmup_lr:
            callbacks.append(warmup_lr)
        if args.cp:
            callbacks.append(checkpointer)
        if args.tb:
            callbacks.append(tensorboard)
        if args.save_weights:
            logger.info("Will save weights to: " + args.save_weights)
            callbacks.append(MultiGPUCheckpoint(args.save_weights))

        if args.use_exported_data is not None:
            train_gen = DataFeeder(
                filename=args.use_exported_data,
                batch_size=args.batch_size,
                shuffle=args.shuffle,
                single=args.single,
                agg_dose=args.agg_dose,
                on_memory=args.on_memory_loader,
            )
            val_gen = DataFeeder(
                partition="val",
                filename=args.use_exported_data,
                batch_size=args.batch_size,
                shuffle=args.shuffle,
                single=args.single,
                agg_dose=args.agg_dose,
                on_memory=args.on_memory_loader,
            )
            test_gen = DataFeeder(
                partition="test",
                filename=args.use_exported_data,
                batch_size=args.batch_size,
                shuffle=args.shuffle,
                single=args.single,
                agg_dose=args.agg_dose,
                on_memory=args.on_memory_loader,
            )
        else:
            train_gen = CombinedDataGenerator(
                loader,
                fold=fold,
                batch_size=args.batch_size,
                shuffle=args.shuffle,
                single=args.single,
            )
            val_gen = CombinedDataGenerator(
                loader,
                partition="val",
                fold=fold,
                batch_size=args.batch_size,
                shuffle=args.shuffle,
                single=args.single,
            )
            test_gen = CombinedDataGenerator(
                loader,
                partition="test",
                fold=fold,
                batch_size=args.batch_size,
                shuffle=args.shuffle,
                single=args.single,
            )

        df_val = val_gen.get_response(copy=True)
        y_val = df_val[target].values
        y_shuf = np.random.permutation(y_val)
        log_evaluation(
            evaluate_prediction(y_val, y_shuf),
            logger,
            description="Between random pairs in y_val:",
        )

        if args.no_gen:
            x_train_list, y_train = train_gen.get_slice(
                size=train_gen.size, single=args.single
            )
            x_val_list, y_val = val_gen.get_slice(size=val_gen.size, single=args.single)
            history = model.fit(
                x_train_list,
                y_train,
                batch_size=args.batch_size,
                epochs=args.epochs,
                callbacks=callbacks,
                validation_data=(x_val_list, y_val),
            )
        else:
            logger.info(
                "Data points per epoch: train = %d, val = %d, test = %d",
                train_gen.size,
                val_gen.size,
                test_gen.size,
            )
            logger.info(
                "Steps per epoch: train = %d, val = %d, test = %d",
                train_gen.steps,
                val_gen.steps,
                test_gen.steps,
            )
            history = model.fit(
                train_gen,
                epochs=args.epochs,
                callbacks=callbacks,
                validation_data=val_gen,
            )

        # prediction on holdout(test) when exists or use validation set
        if test_gen.size > 0:
            df_val = test_gen.get_response(copy=True)
            y_val = df_val[target].values
            y_val_pred = model.predict(test_gen, steps=test_gen.steps + 1)
            y_val_pred = y_val_pred[: test_gen.size]
        else:
            if args.no_gen:
                y_val_pred = model.predict(x_val_list, batch_size=args.batch_size)
            else:
                val_gen.reset()
                y_val_pred = model.predict(val_gen, steps=val_gen.steps + 1)
                y_val_pred = y_val_pred[: val_gen.size]

        y_val_pred = y_val_pred.flatten()

        scores = evaluate_prediction(y_val, y_val_pred)
        log_evaluation(scores, logger)

        # df_val = df_val.assign(PredictedGrowth=y_val_pred, GrowthError=y_val_pred - y_val)
        df_val["Predicted" + target] = y_val_pred
        df_val[target + "Error"] = y_val_pred - y_val
        df_pred_list.append(df_val)

        candle.plot_metrics(
            history,
            title=None,
            skip_ep=0,
            outdir=os.path.dirname(args.save_path),
            add_lr=True,
        )

    pred_fname = prefix + ".predicted.tsv"
    df_pred = pd.concat(df_pred_list)
    if args.agg_dose:
        if args.single:
            df_pred.sort_values(["Sample", "Drug1", target], inplace=True)
        else:
            df_pred.sort_values(
                ["Source", "Sample", "Drug1", "Drug2", target], inplace=True
            )
    else:
        if args.single:
            df_pred.sort_values(["Sample", "Drug1", "Dose1", "Growth"], inplace=True)
        else:
            df_pred.sort_values(
                ["Sample", "Drug1", "Drug2", "Dose1", "Dose2", "Growth"], inplace=True
            )
    df_pred.to_csv(pred_fname, sep="\t", index=False, float_format="%.4g")

    if args.cv > 1:
        scores = evaluate_prediction(df_pred[target], df_pred["Predicted" + target])
        log_evaluation(scores, logger, description="Combining cross validation folds:")

    for test_source in loader.test_sep_sources:
        test_gen = CombinedDataGenerator(
            loader, partition="test", batch_size=args.batch_size, source=test_source
        )
        df_test = test_gen.get_response(copy=True)
        y_test = df_test[target].values
        n_test = len(y_test)
        if n_test == 0:
            continue
        if args.no_gen:
            x_test_list, y_test = test_gen.get_slice(
                size=test_gen.size, single=args.single
            )
            y_test_pred = model.predict(x_test_list, batch_size=args.batch_size)
        else:
            y_test_pred = model.predict_generator(
                test_gen.flow(single=args.single), test_gen.steps
            )
            y_test_pred = y_test_pred[: test_gen.size]
        y_test_pred = y_test_pred.flatten()
        scores = evaluate_prediction(y_test, y_test_pred)
        log_evaluation(
            scores,
            logger,
            description="Testing on data from {} ({})".format(test_source, n_test),
        )

    if K.backend() == "tensorflow":
        K.clear_session()

    logger.handlers = []

    return history

def main():
    params = initialize_parameters()
    run(params)

if __name__ == "__main__":
    main()
    if K.backend() == "tensorflow":
        K.clear_session()


text:
from m5.params import *
from m5.objects.Probe import ProbeListenerObject

class SimPoint(ProbeListenerObject):
    """Probe for collecting SimPoint Basic Block Vectors (BBVs)."""

    type = 'SimPoint'
    cxx_header = "cpu/simple/probes/simpoint.hh"
    cxx_class = 'gem5::SimPoint'

    interval = Param.UInt64(100000000, "Interval Size (insts)")
    profile_file = Param.String("simpoint.bb.gz", "BBV (output) file")


text:
.. _RLCD_example:

Simulation of an electrical oscillator supplying a resistor through a half-wave rectifier
-----------------------------------------------------------------------------------------

Author: Pascal Denoyelle, September 22, 2005

You may refer to the source code of this example, `found here <https://github.com/siconos/siconos/blob/master/examples/Electronics/CircuitRLCD/CircuitRLCD.cpp>`_.

There is also a PDF version of this document, `viewable online here <https://github.com/siconos/siconos/blob/master/examples/Electronics/CircuitRLCD/Template-CircuitRLCD.pdf>`_.

Description of the physical problem : electrical oscillator with half-wave rectifier
````````````````````````````````````````````````````````````````````````````````````

In this sample, a LC oscillator initialized with a given voltage
across the capacitor and a null current through the inductor provides
the energy to a load resistance through a half-wave rectifier
consisting of an ideal diode (see :ref:`fig-CircuitRLCD`).

.. _fig-CircuitRLCD:

.. figure:: /figures/electronics/CircuitRLCD/SchemaCircuitRLCD.*
   :align: center

   fig 1: Electrical oscillator with half-wave rectifier

Only the positive wave of the oscillating voltage across the LC is
provided to the resistor. The energy is dissipated in the resistor
resulting in a damped oscillation.

Definition of a general abstract class of NSDS : the linear time invariant complementarity system (LCS)
```````````````````````````````````````````````````````````````````````````````````````````````````````

This type of non-smooth dynamical system consists of :

* a time invariant linear dynamical system (the oscillator). The state
  variable of this system is denoted by :math:`x`.

* a non-smooth law describing the behaviour of the diode as a
  complementarity condition between current and reverse voltage
  (variables (:math:`y,\lambda`) )

* a linear time invariant relation between the state variable
  :math:`x` and the non-smooth law variables (:math:`y,\lambda`)

Dynamical system and Boundary conditions
''''''''''''''''''''''''''''''''''''''''

Remark:

.. pull-quote::

   In a more general setting, the system's evolution would be
   described by a DAE :

   .. math::

      G \cdot x' = A \cdot x + E \cdot u + b + r

   with :math:`G , A , E` matrices constant over time (time invariant
   system), :math:`u , b` source terms functions of time and
   :math:`r`, a term coming from the non-smooth law variables :
   :math:`r = B \cdot \lambda + a` with :math:`B , a` constant over
   time.  We will consider here the case of an ordinary differential
   equation :

   .. math::

      x' = A \cdot x + E \cdot u + b + r

   and an initial value problem for which the boundary conditions are
   :math:`t_0 \in \mathbb{R} , x(t_0)= x_0`.

Relation between constrained variables and state variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

In the linear time invariant framework, the non-smooth law acts on the
linear dynamical system evolution through the variable :math:`r = B
\cdot \lambda + a`. Reciprocally, the state variable :math:`x` acts on the
non-smooth law through the relation :math:`y = C \cdot x + D \cdot
\lambda + F \cdot u + e` with :math:`C , D , F , e` constant over
time.

Definition of the Non Smooth Law between constrained variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

It is a complementarity condition between y and :math:`\lambda` :
:math:`0 \leq y \, \perp \, \lambda \geq 0`. This corresponds to the
behaviour of the rectifying diode, as described in
:ref:`non-smooth-laws`.

The formalization of the electrical oscillator with half-wave rectifier into the LCS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

The equations come from the following physical laws :

* the Kirchhoff current law (KCL) establishes that the sum of the
  currents arriving at a node is zero,
* the Kirchhoff voltage law (KVL) establishes that the sum of the
  voltage drops in a loop is zero,
* the branch constitutive equations define the relation between the
  current through a bipolar device and the voltage across it

Refering to :ref:`fig-CircuitRLCD`, the Kirchhoff laws could be written as:

.. math::

   \begin{array}{l}
   v_L = v_C\\
   v_R + v_D = v_C\\
   i_C + i_L + i_R = 0\\
   i_R = i_D
   \end{array}

while the branch constitutive equations for linear devices are:

.. math::

   \begin{array}{l}
   i_C = C v_C'\\
   v_L = L i_L'\\
   v_R = R i_R
   \end{array}

and last the "branch constitutive equation" of the ideal diode that is
no more an equation but instead a complementarity condition:

.. math::

   0 \leq i_D \, \perp \, -v_D \geq 0

This is illustrated in :ref:`fig-diode-reg`, where the left-hand
sketch displays the ideal diode characteristic and the right-hand
sketch displays the usual exponential characteristic as stated by
Shockley's law.

.. _fig-diode-reg:

.. figure:: /figures/electronics/CircuitRLCD/diode-caract.*
   :align: center
   :width: 13cm

   fig 2: Non-smooth and smooth characteristics of a diode

.. _sec-dyn-eq:

Dynamical equation
''''''''''''''''''

After rearranging the previous equations, we obtain:

.. math::

   \left( \begin{array}{c}
   v_L'\\
   i_L'
   \end{array} \right)
   =
   \left( \begin{array}{cc}
   0 & \frac{-1}{C}\\
   \frac{1}{L} & 0
   \end{array} \right)
   \cdot
   \left( \begin{array}{c}
   v_L\\
   i_L
   \end{array} \right)
   +
   \left( \begin{array}{c}
   \frac{-1}{C}\\
   0
   \end{array} \right)
   \cdot i_D

that fits in the frame of \ref{sec-def-NSDS} with

.. math::

   x =
   \left( \begin{array}{c}
   v_L\\
   i_L
   \end{array} \right)

and

.. math:: \lambda = i_D

Relations
'''''''''

We recall that the :math:`r = B \cdot \lambda + a` equation is expressed with

.. math::

   r =
   \left( \begin{array}{c}
   \frac{-1}{C}\\
   0
   \end{array} \right)
   \cdot i_D

from the dynamical equation (:ref:`sec-dyn-eq`).

Rearranging the initial set of equations yields:

.. math::

   -v_D =
   \left( \begin{array}{cc}
   -1 & 0
   \end{array} \right)
   \cdot
   \left( \begin{array}{c}
   v_L\\
   i_L
   \end{array} \right)
   + R i_D

as the second equation of the linear time invariant relation with

.. math:: y = -v_D

.. _non-smooth-laws:

Non Smooth laws
'''''''''''''''

There is just the complementarity condition resulting from the ideal diode characteristic:

.. math:: 0 \leq i_D \, \perp \, -v_D \geq 0

Description of the numerical simulation: the Moreau's time-stepping scheme
``````````````````````````````````````````````````````````````````````````

Time discretization of the dynamical system
'''''''''''''''''''''''''''''''''''''''''''

The integration of the ODE over a time step :math:`[t_i,t_{i+1}]` of length :math:`h` is:

.. math::

   \int_{t_i}^{t_{i+1}}x'\,dt = \int_{t_i}^{t_{i+1}}
   A \cdot x\,dt + \int_{t_i}^{t_{i+1}}(E \cdot u + b) dt
   + \int_{t_i}^{t_{i+1}}r\,dt

The left-hand term is :math:`x(t_{i+1})-x(t_i)`.

Right-hand terms are approximated this way:

* :math:`\int_{t_i}^{t_{i+1}} A \cdot x\,dt` is approximated using a
  :math:`\theta`-method

  .. math::

     \int_{t_i}^{t_{i+1}} A \cdot x\,dt \approx h \theta
     (A \cdot x(t_{i+1})) + h (1-\theta) (A \cdot x(t_{i}))

* since the second integral comes from independent sources, it can be
  evaluated with whatever quadrature method, for instance a
  :math:`\theta`-method

  .. math::

     \int_{t_i}^{t_{i+1}}(E \cdot u + b) dt \approx h \theta
     (E \cdot u(t_{i+1}) + b(t_{i+1})) +
     h (1-\theta) (E \cdot u(t_{i}) + b(t_{i}))

* the third integral is approximated like in an implicit Euler integration

  .. math:: \int_{t_i}^{t_{i+1}}r\,dt \approx h r(t_{i+1})

By replacing the accurate solution :math:`x(t_i)` by the approximated value :math:`x_i`, we get:

.. math::

   x_{i+1}-x_i = h \theta (A \cdot x_{i+1}) + h (1-\theta) (A \cdot x_{i}) +
                 h \theta (E \cdot u(t_{i+1}) + b(t_{i+1})) + h (1-\theta) (E \cdot u(t_{i}) + b(t_{i})) + h r_{i+1}

Assuming that :math:`I - h \theta A` is invertible, matrix :math:`W`
is defined as :math:`(I - h \theta A)^{-1}`. We get then:

.. math::

   x_{i+1} = W(I + h (1-\theta) A) \cdot x_{i} +
             W (h \theta (E \cdot u(t_{i+1}) + b(t_{i+1})) + h (1-\theta) (E \cdot u(t_{i}) + b(t_{i}))) + h W r_{i+1}

An intermediate variable :math:`x_{free}` related to the smooth part of the system is defined as:

.. math::

   x_{free} = W(I + h (1-\theta) A) \cdot x_{i} +
              W (h \theta (E \cdot u(t_{i+1}) + b(t_{i+1})) + h (1-\theta) (E \cdot u(t_{i}) + b(t_{i})))

Thus the calculus of :math:`x_{i+1}` becomes:

.. math:: x_{i+1} = x_{free} + h W r_{i+1}

Time discretization of the relations
''''''''''''''''''''''''''''''''''''

It comes straightforwardly:

.. math::

   r_{i+1} =& B \cdot \lambda_{i+1} + a

   y_{i+1} =& C \cdot x_{i+1} + D \cdot \lambda_{i+1} + F \cdot u(t_{i+1}) + e

Time discretization of the non-smooth law
'''''''''''''''''''''''''''''''''''''''''

It comes straightforwardly:

.. math:: 0 \leq y_{i+1} \, \perp \, \lambda_{i+1} \geq 0

Summary of the time discretized equations
'''''''''''''''''''''''''''''''''''''''''

These equations are summarized assuming that there is no source term
and simplified relations as for the electrical oscillator with
half-wave rectifier.

.. math::

   \begin{array}{ccc}
   W & = & (I - h \theta A)^{-1} \\
   x_{free} & = & W(I + h (1-\theta) A) \cdot x_{i} \\
   x_{i+1} & = & x_{free} + h W r_{i+1} \\
   r_{i+1} & = & B \cdot \lambda_{i+1}  \\
   y_{i+1} & = & C \cdot x_{i+1} + D \cdot \lambda_{i+1}  \\
   & 0 \leq y_{i+1} \, \perp \, \lambda_{i+1} \geq 0 &
   \end{array}

Numerical simulation
''''''''''''''''''''

The integration algorithm with a fixed step is described here :

   **Algorthm 1**: Integration of the electrical oscillator with half-wave
   rectifier through a fixed Moreau time stepping scheme

   **Require:** :math:`R > 0 , L > 0 , C > 0`

   **Require:** Time parameters :math:`h,T,t_0` and :math:`\theta` for the integration

   **Require:** Initial value of inductor voltage :math:`v_L = x_0(0)`

   **Require:** Optional, initial value  of inductor current :math:`i_L = x_0(1)` (default: 0)

   :math:`n_{step} = \frac{T - t_0}{h}`

   // *Dynamical system specification*

   :math:`A = \left( \begin{array}{cc} 0 & \frac{-1}{C}\\\frac{1}{L} & 0 \end{array} \right)`

   // *Relation specification*

   :math:`B = \left( \begin{array}{c}\frac{-1}{C}\\0\end{array} \right)`

   :math:`C = \left( \begin{array}{cc}-1 & 0\end{array} \right)`

   :math:`D = (R)`

   // *Construction of time independent operators*

   **Require:** :math:`I - h \theta A` invertible
   :math:`W = (I - h \theta A)^{-1}`
   :math:`M = D + h C W B`

   // *Non-smooth dynamical system integration*

   **for** :math:`i=0` to :math:`n_{step}-1` **do**

   .. math::

      x_{free} =& W (I + h (1 - \theta) A) x_i && \textrm{// Computation of $x_{free}$}

      q =& C \cdot x_{free} &&  \textrm{// Formalization of the one step LCP}

      (y_{i+1},\lambda_{i+1}) =& \textrm{solveLCP}(M,q) &&  \textrm{// One step LCP solving}

      x_{i+1} =& x_{free} + h W B \lambda_{i+1} &&  \textrm{// Computation of new state}

   **end for**

Comparison with numerical results coming from SPICE models and algorithms
`````````````````````````````````````````````````````````````````````````

We have used the SMASH simulator from Dolphin to perform a simulation
of this circuit with a smooth model of the diode as given by
Shockley's law , with a classical one step solver (Newton-Raphson) and
a choice between backward-Euler and trapezoidal integrators.

Characteristic of the diode in the SPICE model
''''''''''''''''''''''''''''''''''''''''''''''

:ref:`fig-carac-diode` depicts the static :math:`I(V)` characteristic
of two diodes with default SPICE parameters and two values for the
emission coefficient :math:`N`: 1.0 (standard diode) and 0.25 (stiff
diode).

.. _fig-carac-diode:

.. figure:: /figures/electronics/CircuitRLCD/caracdiode.*
   :align: center
   :width: 13cm

   fig 3: Diodes characteristics from SPICE model :math:`(N=0.25, N=1)`

The stiff diode is close to an ideal one with a threshold of 0.2 V.

Simulation results
''''''''''''''''''

:ref:`fig-comp-SMASH-SICONOS-BE10us` displays a comparison of the
SMASH and SICONOS results with a backward Euler integration and a
fixed time step of 10 μs. A stiff diode model was used in SMASH
simulations.  For :ref:`fig-comp-SMASH-SICONOS-TRAP10us`, a
trapezoidal integrator was used, yielding a better accuracy.  One can
notice that the results from both simulators are very close. The
slight differences are due to the smooth model of the diode used by
SMASH, and mainly to the threshold of around 0.2 V. Such a threshold
yields small differences in the conduction state of the diode with
respect to the ideal diode.

.. _fig-comp-SMASH-SICONOS-BE10us:

.. figure:: /figures/electronics/CircuitRLCD/comp_SMASH_SICONOS_BE10us.*
   :align: center
   :width: 13cm

   fig 4: SMASH and SICONOS simulation results with backward Euler
   integration, 10 μs time step

.. _fig-comp-SMASH-SICONOS-TRAP10us:

.. figure:: /figures/electronics/CircuitRLCD/comp_SMASH_SICONOS_TRAP10us.*
   :align: center
   :width: 13cm

   fig 5: SMASH and SICONOS simulation results with trapezoidal
   integration, 10 μs time step


text:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Setting Durability Guarantees</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Getting Started with Oracle NoSQL Database Tables" />
    <link rel="up" href="durability.html" title="Chapter 11. Durability Guarantees" />
    <link rel="prev" href="durability-sync.html" title="Setting Synchronization-Based Durability Policies" />
    <link rel="next" href="multiop.html" title="Chapter 12. Executing a Sequence of Operations" />

Library Version 12.1.3.5

          Setting Durability Guarantees

          Prev
          Chapter 11. Durability Guarantees
           Next

Setting Durability Guarantees

              To set a durability guarantee, use the
              Durability class. When you do this,
              you must provide three pieces of information:

                      The acknowledgment policy.

                      A synchronization policy at the master node.

                      A synchronization policy at the replica nodes.

              The combination of policies that you use is driven by how
              sensitive your application might be to potential data loss,
              and by your write performance requirements.

              For example, the fastest possible write performance can be
              achieved through a durability policy that requires:

                      No acknowledgments.

                      NO_SYNC at the master.

                      NO_SYNC at the replicas.

              However, this durability policy also leaves your data with
              the greatest risk of loss due to application or machine
              failure between the time the operation returns and the time
              when the data is written to stable storage.

              On the other hand, if you want the highest possible
              durability guarantee, you can use:

                      All replicas must acknowledge the write operation.

                        SYNC at the master.

                      SYNC at the replicas.

              Of course, this also results in the slowest possible write
              performance.

              Most commonly, durability policies attempt to strike a
              balance between write performance and data durability
              guarantees. For example:

                      Simple majority of replicas must acknowledge the
                      write.

                      SYNC at the master.

                      NO_SYNC at the replicas.

              Note that you can set a default durability policy for your
              KVStore

              handle, but you can also
              override the policy on a per-operation basis for those
              situations where some of your data need not be as durable (or
              needs to be MORE durable) than the default.

              For example, suppose you want an intermediate durability
              policy for most of your data, but sometimes you have
              transient or easily re-created data whose durability really
              is not very important. Then you would do something like this:

              First, set the default durability policy for the
              KVStore

              handle:

package kvstore.basicExample;

import oracle.kv.Durability;
import oracle.kv.KVStore;
import oracle.kv.KVStoreConfig;
import oracle.kv.KVStoreFactory;

...

KVStoreConfig kconfig = new KVStoreConfig("exampleStore",
    "node1.example.org:5088, node2.example.org:4129");

Durability defaultDurability =
    new Durability(Durability.SyncPolicy.SYNC,    // Master sync
                   Durability.SyncPolicy.NO_SYNC, // Replica sync
                   Durability.ReplicaAckPolicy.SIMPLE_MAJORITY);
kconfig.setDurability(defaultDurability);

KVStore kvstore = KVStoreFactory.getStore(kconfig);

                In another part of your code, for some unusual write
                operations, you might then want to relax the
                durability guarantee so as to speed up the write
                performance for those specific write operations:

package kvstore.basicExample;

...

import oracle.kv.Durability;
import oracle.kv.DurabilityException;
import oracle.kv.KVStore;
import oracle.kv.table.Row;
import oracle.kv.table.Table;
import oracle.kv.table.TableAPI;

...

TableAPI tableH = kvstore.getTableAPI();

// The name you give to getTable() must be identical
// to the name that you gave the table when you created
// the table using the CREATE TABLE DDL statement.
Table myTable = tableH.getTable("myTable");

// Get a Row instance
Row row = myTable.createRow();

// Now put all of the cells in the row.

row.put("item", "Bolts");
row.put("description", "Hex head, stainless");
row.put("count", 5);
row.put("percentage", 0.2173913);

// Construct a durability policy
Durability durability =
    new Durability(Durability.SyncPolicy.NO_SYNC, // Master sync
                   Durability.SyncPolicy.NO_SYNC, // Replica sync
                   Durability.ReplicaAckPolicy.NONE);

// Construct a WriteOptions object using the durability policy.
WriteOptions wo = new WriteOptions(durability, 0, null);

// Now write the table to the store using the durability policy
// defined, above.
tableH.put(row, null, wo);

          Prev

            Up

           Next

          Setting Synchronization-Based Durability Policies

            Home

           Chapter 12. Executing a Sequence of Operations