DQCsim
Public Member Functions | List of all members
dqcsim::wrap::Simulation Class Reference

Wrapper class for a running simulation. More...

Inheritance diagram for dqcsim::wrap::Simulation:
dqcsim::wrap::Handle

Public Member Functions

 Simulation (HandleIndex handle) noexcept
 Wraps the given simulation handle. More...
 
 Simulation (const Simulation &)=delete
 
void operator= (const Simulation &)=delete
 
 Simulation (Simulation &&)=default
 Default move constructor.
 
Simulationoperator= (Simulation &&)=default
 Default move assignment.
 
void start ()
 Starts a program on the simulated accelerator without an argument. More...
 
void start (ArbData &&data)
 Starts a program on the simulated accelerator using the given ArbData object as an argument (passed by move). More...
 
void start (const ArbData &data)
 Starts a program on the simulated accelerator using the given ArbData object as an argument (passed by copy). More...
 
ArbData wait ()
 Waits for the simulated accelerator to finish its current program. More...
 
ArbData run ()
 Runs a program on the simulated accelerator without an argument. More...
 
ArbData run (ArbData &&data)
 Runs a program on the simulated accelerator using the given ArbData object as an argument (passed by move). More...
 
ArbData run (const ArbData &data)
 Runs a program on the simulated accelerator using the given ArbData object as an argument (passed by copy). More...
 
void send ()
 Sends an empty message to the simulated accelerator. More...
 
void send (ArbData &&data)
 Sends the given ArbData message to the simulated accelerator (passed by move). More...
 
void send (const ArbData &data)
 Sends the given ArbData message to the simulated accelerator (passed by copy). More...
 
ArbData recv ()
 Waits for the simulated accelerator to send a message to us. More...
 
void yield ()
 Yields to the simulator. More...
 
ArbData arb (const std::string &name, ArbCmd &&cmd)
 Sends an ArbCmd (passed by move) to the given plugin (referenced by instance name). More...
 
ArbData arb (const std::string &name, const ArbCmd &cmd)
 Sends an ArbCmd (passed by copy) to the given plugin (referenced by instance name). More...
 
ArbData arb (ssize_t index, ArbCmd &&cmd)
 Sends an ArbCmd (passed by move) to the given plugin (referenced by index). More...
 
ArbData arb (ssize_t index, const ArbCmd &cmd)
 Sends an ArbCmd (passed by copy) to the given plugin (referenced by index). More...
 
std::string get_name (const std::string &name)
 Queries the class name of a plugin, referenced by instance name. More...
 
std::string get_name (ssize_t index)
 Queries the class name of a plugin, referenced by index. More...
 
std::string get_author (const std::string &name)
 Queries the author of a plugin, referenced by instance name. More...
 
std::string get_author (ssize_t index)
 Queries the author of a plugin, referenced by index. More...
 
std::string get_version (const std::string &name)
 Queries the version of a plugin, referenced by instance name. More...
 
std::string get_version (ssize_t index)
 Queries the version of a plugin, referenced by index. More...
 
void write_reproduction_file (const std::string &filename)
 Writes a reproduction file for the simulation so far. More...
 
- Public Member Functions inherited from dqcsim::wrap::Handle
 Handle () noexcept
 Constructs an empty wrapper. More...
 
 Handle (HandleIndex handle) noexcept
 Wraps the given raw handle. More...
 
virtual ~Handle () noexcept
 Delete the handle and its wrapper.
 
void free ()
 Explicitly delete the handle, allowing errors to be caught. More...
 
bool is_valid () const noexcept
 Returns whether this wrapper (still) contains a valid handle. More...
 
HandleIndex get_handle () const noexcept
 Returns the raw handle without relinquishing ownership. More...
 
HandleIndex take_handle () noexcept
 Returns the raw handle and relinquishes ownership. More...
 
 Handle (const Handle &)=delete
 
void operator= (const Handle &)=delete
 
 Handle (Handle &&src)
 Move constructor; simply moves ownership of the handle from the source object to the constructed object. More...
 
Handleoperator= (Handle &&src)
 Move constructor; simply moves ownership of the handle from the source object to the assignment target. More...
 
std::string dump () const
 Returns a string containing a debug dump of the handle. More...
 
HandleType type () const
 Returns the type of this handle. More...
 

Additional Inherited Members

- Protected Attributes inherited from dqcsim::wrap::Handle
HandleIndex handle
 The wrapped handle.
 

Detailed Description

Wrapper class for a running simulation.

Definition at line 9461 of file dqcsim.

Constructor & Destructor Documentation

◆ Simulation()

dqcsim::wrap::Simulation::Simulation ( HandleIndex  handle)
inlinenoexcept

Wraps the given simulation handle.

Note
This constructor does not verify that the handle is actually valid.
Parameters
handleThe raw handle to wrap.

Definition at line 9472 of file dqcsim.

Member Function Documentation

◆ start() [1/3]

void dqcsim::wrap::Simulation::start ( )
inline

Starts a program on the simulated accelerator without an argument.

What constitutes "running a program" depends on the frontend plugin.

Note
This is an asynchronous call: nothing happens until yield(), recv(), wait(), or run() is called.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state.

Definition at line 9499 of file dqcsim.

◆ start() [2/3]

void dqcsim::wrap::Simulation::start ( ArbData &&  data)
inline

Starts a program on the simulated accelerator using the given ArbData object as an argument (passed by move).

What constitutes "running a program" depends on the frontend plugin.

Note
This is an asynchronous call: nothing happens until yield(), recv(), wait(), or run() is called.
Parameters
dataAn ArbData object to pass to the plugin's run callback.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state.

Definition at line 9515 of file dqcsim.

◆ start() [3/3]

void dqcsim::wrap::Simulation::start ( const ArbData data)
inline

Starts a program on the simulated accelerator using the given ArbData object as an argument (passed by copy).

What constitutes "running a program" depends on the frontend plugin.

Note
This is an asynchronous call: nothing happens until yield(), recv(), wait(), or run() is called.
Parameters
dataAn ArbData object to pass to the plugin's run callback.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state.

Definition at line 9531 of file dqcsim.

◆ wait()

ArbData dqcsim::wrap::Simulation::wait ( )
inline

Waits for the simulated accelerator to finish its current program.

Returns
The ArbData object that was returned by the frontend plugin's implementation of the run callback.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state or a deadlock occurs because the frontend is waiting for a call to send().

Definition at line 9544 of file dqcsim.

◆ run() [1/3]

ArbData dqcsim::wrap::Simulation::run ( )
inline

Runs a program on the simulated accelerator without an argument.

This is just a shorthand for start() followed by wait().

Returns
The ArbData object that was returned by the frontend plugin's implementation of the run callback.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state or a deadlock occurs because the frontend is waiting for a call to send().

Definition at line 9559 of file dqcsim.

◆ run() [2/3]

ArbData dqcsim::wrap::Simulation::run ( ArbData &&  data)
inline

Runs a program on the simulated accelerator using the given ArbData object as an argument (passed by move).

This is just a shorthand for start() followed by wait().

Parameters
dataAn ArbData object to pass to the plugin's run callback.
Returns
The ArbData object that was returned by the frontend plugin's implementation of the run callback.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state or a deadlock occurs because the frontend is waiting for a call to send().

Definition at line 9577 of file dqcsim.

◆ run() [3/3]

ArbData dqcsim::wrap::Simulation::run ( const ArbData data)
inline

Runs a program on the simulated accelerator using the given ArbData object as an argument (passed by copy).

This is just a shorthand for start() followed by wait().

Parameters
dataAn ArbData object to pass to the plugin's run callback.
Returns
The ArbData object that was returned by the frontend plugin's implementation of the run callback.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state or a deadlock occurs because the frontend is waiting for a call to send().

Definition at line 9595 of file dqcsim.

◆ send() [1/3]

void dqcsim::wrap::Simulation::send ( )
inline

Sends an empty message to the simulated accelerator.

Note
This is an asynchronous call: nothing happens until yield(), recv(), wait(), or run() is called.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state.

Definition at line 9608 of file dqcsim.

◆ send() [2/3]

void dqcsim::wrap::Simulation::send ( ArbData &&  data)
inline

Sends the given ArbData message to the simulated accelerator (passed by move).

Note
This is an asynchronous call: nothing happens until yield(), recv(), wait(), or run() is called.
Parameters
dataThe ArbData object to send to the plugin.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state.

Definition at line 9622 of file dqcsim.

◆ send() [3/3]

void dqcsim::wrap::Simulation::send ( const ArbData data)
inline

Sends the given ArbData message to the simulated accelerator (passed by copy).

Note
This is an asynchronous call: nothing happens until yield(), recv(), wait(), or run() is called.
Parameters
dataThe ArbData object to send to the plugin.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state.

Definition at line 9636 of file dqcsim.

◆ recv()

ArbData dqcsim::wrap::Simulation::recv ( )
inline

Waits for the simulated accelerator to send a message to us.

Returns
The ArbData sent to us.
Exceptions
std::runtime_errorWhen the simulation is in an invalid state or when the plugin's run callback returned before sending (more) data.

Definition at line 9647 of file dqcsim.

◆ yield()

void dqcsim::wrap::Simulation::yield ( )
inline

Yields to the simulator.

The simulation runs until it blocks again. This is useful if you want an immediate response to an otherwise asynchronous call through the logging system or some communication channel outside of DQCsim's control.

This function silently returns immediately if no asynchronous data was pending or if the simulator is waiting for something that has not been sent yet.

Exceptions
std::runtime_errorWhen the simulation is in an invalid state.

Definition at line 9664 of file dqcsim.

◆ arb() [1/4]

ArbData dqcsim::wrap::Simulation::arb ( const std::string &  name,
ArbCmd &&  cmd 
)
inline

Sends an ArbCmd (passed by move) to the given plugin (referenced by instance name).

ArbCmds are executed immediately after yielding to the simulator, so all pending asynchronous calls are flushed and executed before the ArbCmd.

Parameters
nameThe instance name of the plugin to send the command to.
cmdThe command to send.
Returns
The ArbData object returned by the command.
Exceptions
std::runtime_errorWhen the given name does not identify a plugin, the command failed, or the simulation is in an invalid state.

Definition at line 9682 of file dqcsim.

◆ arb() [2/4]

ArbData dqcsim::wrap::Simulation::arb ( const std::string &  name,
const ArbCmd cmd 
)
inline

Sends an ArbCmd (passed by copy) to the given plugin (referenced by instance name).

ArbCmds are executed immediately after yielding to the simulator, so all pending asynchronous calls are flushed and executed before the ArbCmd.

Parameters
nameThe instance name of the plugin to send the command to.
cmdThe command to send.
Returns
The ArbData object returned by the command.
Exceptions
std::runtime_errorWhen the given name does not identify a plugin, the command failed, or the simulation is in an invalid state.

Definition at line 9700 of file dqcsim.

◆ arb() [3/4]

ArbData dqcsim::wrap::Simulation::arb ( ssize_t  index,
ArbCmd &&  cmd 
)
inline

Sends an ArbCmd (passed by move) to the given plugin (referenced by index).

ArbCmds are executed immediately after yielding to the simulator, so all pending asynchronous calls are flushed and executed before the ArbCmd.

Parameters
indexThe index of the plugin to send the command to. The frontend always has index 0. 1 through N are used for the operators in front to back order (where N is the number of operators). The backend is at index N+1. Python-style negative indices are also supported. That is, -1 can be used to refer to the backend, -2 to the last operator, and so on.
cmdThe command to send.
Returns
The ArbData object returned by the command.
Exceptions
std::runtime_errorWhen the given index is out of range, the command failed, or the simulation is in an invalid state.

Definition at line 9722 of file dqcsim.

◆ arb() [4/4]

ArbData dqcsim::wrap::Simulation::arb ( ssize_t  index,
const ArbCmd cmd 
)
inline

Sends an ArbCmd (passed by copy) to the given plugin (referenced by index).

ArbCmds are executed immediately after yielding to the simulator, so all pending asynchronous calls are flushed and executed before the ArbCmd.

Parameters
indexThe index of the plugin to send the command to. The frontend always has index 0. 1 through N are used for the operators in front to back order (where N is the number of operators). The backend is at index N+1. Python-style negative indices are also supported. That is, -1 can be used to refer to the backend, -2 to the last operator, and so on.
cmdThe command to send.
Returns
The ArbData object returned by the command.
Exceptions
std::runtime_errorWhen the given index is out of range, the command failed, or the simulation is in an invalid state.

Definition at line 9744 of file dqcsim.

◆ get_name() [1/2]

std::string dqcsim::wrap::Simulation::get_name ( const std::string &  name)
inline

Queries the class name of a plugin, referenced by instance name.

Parameters
nameThe instance name of the plugin to query.
Returns
The class name of the plugin.
Exceptions
std::runtime_errorWhen the given name does not identify a plugin, or when the simulation is in an invalid state.

Definition at line 9756 of file dqcsim.

◆ get_name() [2/2]

std::string dqcsim::wrap::Simulation::get_name ( ssize_t  index)
inline

Queries the class name of a plugin, referenced by index.

Parameters
indexThe index of the plugin to query. The frontend always has index 0. 1 through N are used for the operators in front to back order (where N is the number of operators). The backend is at index N+1. Python-style negative indices are also supported. That is, -1 can be used to refer to the backend, -2 to the last operator, and so on.
Returns
The class name of the plugin.
Exceptions
std::runtime_errorWhen the given index is out of range, or when the simulation is in an invalid state.

Definition at line 9775 of file dqcsim.

◆ get_author() [1/2]

std::string dqcsim::wrap::Simulation::get_author ( const std::string &  name)
inline

Queries the author of a plugin, referenced by instance name.

Parameters
nameThe instance name of the plugin to query.
Returns
The plugin author.
Exceptions
std::runtime_errorWhen the given name does not identify a plugin, or when the simulation is in an invalid state.

Definition at line 9790 of file dqcsim.

◆ get_author() [2/2]

std::string dqcsim::wrap::Simulation::get_author ( ssize_t  index)
inline

Queries the author of a plugin, referenced by index.

Parameters
indexThe index of the plugin to query. The frontend always has index 0. 1 through N are used for the operators in front to back order (where N is the number of operators). The backend is at index N+1. Python-style negative indices are also supported. That is, -1 can be used to refer to the backend, -2 to the last operator, and so on.
Returns
The plugin author.
Exceptions
std::runtime_errorWhen the given index is out of range, or when the simulation is in an invalid state.

Definition at line 9809 of file dqcsim.

◆ get_version() [1/2]

std::string dqcsim::wrap::Simulation::get_version ( const std::string &  name)
inline

Queries the version of a plugin, referenced by instance name.

Parameters
nameThe instance name of the plugin to query.
Returns
The plugin version.
Exceptions
std::runtime_errorWhen the given name does not identify a plugin, or when the simulation is in an invalid state.

Definition at line 9824 of file dqcsim.

◆ get_version() [2/2]

std::string dqcsim::wrap::Simulation::get_version ( ssize_t  index)
inline

Queries the version of a plugin, referenced by index.

Parameters
indexThe index of the plugin to query. The frontend always has index 0. 1 through N are used for the operators in front to back order (where N is the number of operators). The backend is at index N+1. Python-style negative indices are also supported. That is, -1 can be used to refer to the backend, -2 to the last operator, and so on.
Returns
The plugin version.
Exceptions
std::runtime_errorWhen the given index is out of range, or when the simulation is in an invalid state.

Definition at line 9843 of file dqcsim.

◆ write_reproduction_file()

void dqcsim::wrap::Simulation::write_reproduction_file ( const std::string &  filename)
inline

Writes a reproduction file for the simulation so far.

Parameters
filenameThe file to write to.
Exceptions
std::runtime_errorWhen the simulation cannot be reproduced or when it's in an invalid state.

Definition at line 9857 of file dqcsim.


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