Computer algebra system for field theory problems
Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | List of all members
cadabra::CadabraJupyter Class Reference


A Jupyter kernel for Cadabra, which provides the Cadabra pre-processor to enable input as in the Gtk notebook frontend.

Built using Xeus.

#include <cadabra-jupyter-kernel.hh>

Inheritance diagram for cadabra::CadabraJupyter:

Public Member Functions

 CadabraJupyter ()
virtual ~CadabraJupyter ()=default
virtual uint64_t send (const std::string &output, const std::string &msg_type, uint64_t parent_id, bool last) override
 Raw code to send a string (which must be JSON formatted) as a message to the client. More...
- Public Member Functions inherited from Server
 Server ()
 Server (const Server &)=delete
 Server (const std::string &socket)
virtual ~Server ()
void run (int port=0, bool exit_on_disconnect=true)
 The only user-visible part: just instantiate a server object and start it with run(). More...
void send_progress_update (const std::string &msg, int n, int total)
void send_json (const std::string &)
bool handles (const std::string &otype) const
std::string architecture () const
void wait_for_job ()
 Start a thread which waits for blocks to appear on the block queue, and executes them in turn. More...

Public Attributes

int current_counter
bool finished =true
- Public Attributes inherited from Server
CatchOutput catchOut
CatchOutput catchErr
Stopwatch server_stopwatch
Stopwatch sympy_stopwatch

Protected Member Functions

virtual void on_block_error (Block) override
- Protected Member Functions inherited from Server
void init ()
void on_socket_init (websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket &s)
void on_message (websocketpp::connection_hdl hdl, WebsocketServer::message_ptr msg)
void on_open (websocketpp::connection_hdl hdl)
void on_close (websocketpp::connection_hdl hdl)
std::string run_string (const std::string &, bool handle_output=true)
virtual void on_block_finished (Block)
 Called by the run_block() thread upon completion of the task. More...
virtual void on_kernel_fault (Block)
void stop_block ()
 Halt the currently running block and prevent execution of any further blocks that may still be on the queue. More...
void dispatch_message (websocketpp::connection_hdl, const std::string &json_string)
 Takes a JSON encoded message and performs the required action to process it. More...

Private Member Functions

void configure_impl () override
xjson execute_request_impl (int execution_counter, const std::string &code, bool silent, bool store_history, xjson user_expressions, bool allow_stdin) override
xjson complete_request_impl (const std::string &code, int cursor_pos) override
xjson inspect_request_impl (const std::string &code, int cursor_pos, int detail_level) override
xjson is_complete_request_impl (const std::string &code) override
xjson kernel_info_request_impl () override
void shutdown_request_impl () override

Additional Inherited Members

- Protected Types inherited from Server
typedef websocketpp::server< websocketpp::config::asio > WebsocketServer
typedef std::map< websocketpp::connection_hdl, Connection, std::owner_less< websocketpp::connection_hdl > > ConnectionMap
- Protected Attributes inherited from Server
WebsocketServer wserver
std::string socket_name
ConnectionMap connections
std::string authentication_token
std::mutex ws_mutex
std::thread runner
std::mutex block_available_mutex
std::condition_variable block_available
bool exit_on_disconnect
std::queue< Blockblock_queue
websocketpp::connection_hdl current_hdl
uint64_t current_id
bool started
std::future< std::string > job
pybind11::scoped_interpreter guard
pybind11::module main_module
pybind11::object main_namespace

Constructor & Destructor Documentation

◆ CadabraJupyter()

cadabra::CadabraJupyter::CadabraJupyter ( )

◆ ~CadabraJupyter()

virtual cadabra::CadabraJupyter::~CadabraJupyter ( )

Member Function Documentation

◆ complete_request_impl()

xjson cadabra::CadabraJupyter::complete_request_impl ( const std::string &  code,
int  cursor_pos 

◆ configure_impl()

void cadabra::CadabraJupyter::configure_impl ( )

◆ execute_request_impl()

xjson cadabra::CadabraJupyter::execute_request_impl ( int  execution_counter,
const std::string &  code,
bool  silent,
bool  store_history,
xjson  user_expressions,
bool  allow_stdin 

◆ inspect_request_impl()

xjson cadabra::CadabraJupyter::inspect_request_impl ( const std::string &  code,
int  cursor_pos,
int  detail_level 

◆ is_complete_request_impl()

xjson cadabra::CadabraJupyter::is_complete_request_impl ( const std::string &  code)

◆ kernel_info_request_impl()

xjson cadabra::CadabraJupyter::kernel_info_request_impl ( )

◆ on_block_error()

void cadabra::CadabraJupyter::on_block_error ( Block  blk)

Reimplemented from Server.

◆ send()

uint64_t cadabra::CadabraJupyter::send ( const std::string &  output,
const std::string &  msg_type,
uint64_t  parent_id,
bool  last_in_sequence 

Raw code to send a string (which must be JSON formatted) as a message to the client.

Handles communication of the result back to the client in JSON format. This is always of the form

 { "header":   { "parent_id":     "...",
                 "parent_origin": "client" | "server",
                 "cell_id":       "...",
                 "cell_origin":   "client" | "server"
   "content":  { "output":  "..." },
   "msg_type": "..."

msg_type can be "output", "latex", "image_png" and so on, corresponding to the possible values of DataCell::CellType.

Returns the serial number of the new cell sent.

Reimplemented from Server.

◆ shutdown_request_impl()

void cadabra::CadabraJupyter::shutdown_request_impl ( )

Member Data Documentation

◆ current_counter

int cadabra::CadabraJupyter::current_counter

◆ finished

bool cadabra::CadabraJupyter::finished =true

The documentation for this class was generated from the following files: