Main circuit class. More...
Public Types | |
typedef boost::transform_iterator < filter_circuit, boost::indirect_iterator < std::vector < boost::shared_ptr< gate > >::iterator > > | iterator |
Mutable iterator for accessing the gates in a circuit. | |
typedef boost::transform_iterator < const_filter_circuit, boost::indirect_iterator < std::vector < boost::shared_ptr< gate > >::const_iterator > > | const_iterator |
Constant iterator for accessing the gates in a circuit. | |
typedef boost::transform_iterator < filter_circuit, boost::indirect_iterator < std::vector < boost::shared_ptr< gate > >::reverse_iterator > > | reverse_iterator |
Mutable reverse iterator for accessing the gates in a circuit. | |
typedef boost::transform_iterator < const_filter_circuit, boost::indirect_iterator < std::vector < boost::shared_ptr< gate > >::const_reverse_iterator > > | const_reverse_iterator |
Constant reverse iterator for accessing the gates in a circuit. | |
Public Member Functions | |
circuit () | |
Default constructor. More... | |
circuit (const standard_circuit &std_circ) | |
Cast Constructor for a standard_circuit. More... | |
circuit (standard_circuit &std_circ) | |
Cast Constructor for a standard_circuit. More... | |
circuit (const subcircuit &sub_circ) | |
Cast Constructor for a subcircuit. More... | |
circuit (subcircuit &sub_circ) | |
Cast Constructor for a subcircuit. More... | |
circuit (const circuit &other) | |
Copy Constructor. More... | |
unsigned | num_gates () const |
Returns the number of gates. More... | |
void | set_lines (unsigned lines) |
Sets the number of line. More... | |
unsigned | lines () const |
Returns the number of lines. More... | |
const_iterator | begin () const |
Constant begin iterator pointing to gates. More... | |
const_iterator | end () const |
Constant end iterator pointing to gates. More... | |
iterator | begin () |
Mutable begin iterator pointing to gates. More... | |
iterator | end () |
Mutable end iterator pointing to gates. More... | |
const_reverse_iterator | rbegin () const |
Constant begin reverse iterator pointing to gates. More... | |
const_reverse_iterator | rend () const |
Constant end reverse iterator pointing to gates. More... | |
reverse_iterator | rbegin () |
Mutable begin reverse iterator pointing to gates. More... | |
reverse_iterator | rend () |
Mutable end reverse iterator pointing to gates. More... | |
const gate & | operator[] (unsigned index) const |
Random access operator for access to gates by index. More... | |
gate & | operator[] (unsigned index) |
Random access operator for access to gates by index. More... | |
gate & | append_gate () |
Inserts a gate at the end of the circuit. More... | |
gate & | prepend_gate () |
Inserts a gate at the beginning of the circuit. More... | |
gate & | insert_gate (unsigned pos) |
Inserts a gate into the circuit. More... | |
void | remove_gate_at (unsigned pos) |
Removes a gate at a given index. More... | |
void | set_inputs (const std::vector< std::string > &inputs) |
Sets the input names of the lines in a circuit. More... | |
const std::vector< std::string > & | inputs () const |
Returns the input names of the lines in a circuit. More... | |
void | set_outputs (const std::vector< std::string > &outputs) |
Sets the output names of the lines in a circuit. More... | |
const std::vector< std::string > & | outputs () const |
Returns the output names of the lines in a circuit. More... | |
void | set_constants (const std::vector< constant > &constants) |
Sets the constant input line specifications. More... | |
const std::vector< constant > & | constants () const |
Returns the constant input line specification. More... | |
void | set_garbage (const std::vector< bool > &garbage) |
Sets whether outputs are garbage or not. More... | |
const std::vector< bool > & | garbage () const |
Returns whether outputs are garbage or not. More... | |
void | set_circuit_name (const std::string &name) |
Sets a name of the circuit. More... | |
const std::string & | circuit_name () const |
Returns the name of the circuit. More... | |
const bus_collection & | inputbuses () const |
Constant access to the input buses. More... | |
bus_collection & | inputbuses () |
Mutable access to the input buses. More... | |
const bus_collection & | outputbuses () const |
Constant access to the output buses. More... | |
bus_collection & | outputbuses () |
Mutable access to the output buses. More... | |
const bus_collection & | statesignals () const |
Constant access to the state signals. More... | |
bus_collection & | statesignals () |
Mutable access to the state signals. More... | |
bool | is_subcircuit () const |
Returns whether the circuit is a sub-circuit or not. More... | |
std::pair< unsigned, std::vector< unsigned > > | filter () const |
Returns the filter of a sub-circuit. More... | |
unsigned | offset () const |
Returns the offset of the circuit (sub-circuit) More... | |
void | add_module (const std::string &name, const boost::shared_ptr< circuit > &module) |
Adds a module to the circuit. More... | |
void | add_module (const std::string &name, const circuit &module) |
Adds a module to the circuit. More... | |
const std::map< std::string, boost::shared_ptr< circuit > > & | modules () const |
Returns all modules in the circuit. More... | |
const std::string & | annotation (const gate &g, const std::string &key, const std::string &default_value=std::string()) const |
Returns the annotation for one gate and one key. More... | |
boost::optional< const std::map< std::string, std::string > & > | annotations (const gate &g) const |
Returns all annotations for a given gate. More... | |
void | annotate (const gate &g, const std::string &key, const std::string &value) |
Annotates a gate. More... | |
Public Attributes | |
boost::signal< void(gate &)> | gate_added |
Signal which is emitted after adding a gate. More... | |
Main circuit class.
This class represents a circuit and can be used generically for standard circuits and sub circuits.
|
inline |
Default constructor.
This constructor initializes a standard_circuit with 0 lines, also called an empty circuit. Empty circuits are usually used as parameters for parsing functions, optimization algorithms, etc.
|
inline |
Cast Constructor for a standard_circuit.
With this constructor the standard_circuit constructor is automatically converted to a circuit, e.g. by calling
a circuit with 3 lines is created.
std_circ | standard_circuit implementation |
|
inline |
Cast Constructor for a standard_circuit.
With this constructor the standard_circuit constructor is automatically converted to a circuit, e.g. by calling
a circuit with 3 lines is created.
std_circ | standard_circuit implementation |
|
inline |
Cast Constructor for a subcircuit.
This constructor is used, so that subcircuits are detected as circuits in algorithms and can passed as circuit parameter to other functions and algorithms.
sub_circ | subcircuit implementation |
|
inline |
Cast Constructor for a subcircuit.
This constructor is used, so that subcircuits are detected as circuits in algorithms and can passed as circuit parameter to other functions and algorithms.
sub_circ | subcircuit implementation |
Copy Constructor.
This constructor is used by some algorithms, but should not be used directly.
It copies the underlying circuit, but it does not copy the signals, so that this information gets lost.
other | Circuit to be copied |
void add_module | ( | const std::string & | name, |
const boost::shared_ptr< circuit > & | module | ||
) |
Adds a module to the circuit.
This function adds a module to the circuit. It does not create a gate calling the module, but the module itself as a reference for further use, e.g. with append_module.
This method uses smart pointer to a circuit wich already exists and is managed by another object. If it cannot be assured that the module is saved, the method add_module(const std::string&, const circuit&) should be used.
name | Name of the module |
module | Reference to an existing module |
void add_module | ( | const std::string & | name, |
const circuit & | module | ||
) |
Adds a module to the circuit.
This function adds a module to the circuit. It does not create a gate calling the module, but the module itself as a reference for further use, e.g. with append_module.
In this method the module is copied first and thus assured that is managed by this circuit.
name | Name of the module |
module | Module to be copied |
void annotate | ( | const gate & | g, |
const std::string & | key, | ||
const std::string & | value | ||
) |
Annotates a gate.
With this method a gate can be annotated using a key and a value. If there is an annotation with the same key, it will be overwritten.
g | Gate |
key | Key of the annotation |
value | Value of the annotation |
const std::string& annotation | ( | const gate & | g, |
const std::string & | key, | ||
const std::string & | default_value = std::string() |
||
) | const |
Returns the annotation for one gate and one key.
This method returns the value for one particular annotation for a given gate. If no annotation with that key exists, the a default value is given.
g | Gate |
key | Key of the annotation |
default_value | Default value, in case the key does not exist |
boost::optional<const std::map<std::string, std::string>& > annotations | ( | const gate & | g | ) | const |
Returns all annotations for a given gate.
This method returns all annotations for a given gate. For the purpose of efficiency, this method returns an optional data type containing the property map. So, first check whether there are items by assierting the optional, and then go through the map by dereferencing the optional:
g | Gate |
gate& append_gate | ( | ) |
Inserts a gate at the end of the circuit.
This method inserts a gate at the end of the circuit.
const_iterator begin | ( | ) | const |
Constant begin iterator pointing to gates.
iterator begin | ( | ) |
Mutable begin iterator pointing to gates.
const std::string& circuit_name | ( | ) | const |
Returns the name of the circuit.
Returns the name of the circuit which is empty initially.
const std::vector<constant>& constants | ( | ) | const |
Returns the constant input line specification.
This method returns the constant input line specification.
const_iterator end | ( | ) | const |
Constant end iterator pointing to gates.
iterator end | ( | ) |
Mutable end iterator pointing to gates.
std::pair<unsigned, std::vector<unsigned> > filter | ( | ) | const |
Returns the filter of a sub-circuit.
This method returns a pair (l, f). In case the circuit is sub-circuit restricted on the lines, l is the original number of lines of the base circuit and f is the filter, i.e. a vector of lines which are used for the sub-circuit. In other cases s is always 0 and f is empty.
const std::vector<bool>& garbage | ( | ) | const |
Returns whether outputs are garbage or not.
This method returns the garbage line specification.
const bus_collection& inputbuses | ( | ) | const |
Constant access to the input buses.
This method gives constant access to the input buses.
bus_collection& inputbuses | ( | ) |
Mutable access to the input buses.
This method gives mutable access to the input buses.
const std::vector<std::string>& inputs | ( | ) | const |
Returns the input names of the lines in a circuit.
This method returns the input names of the lines in a circuit. This is useful for functions when writing them to a file, printing them, or creating images.
gate& insert_gate | ( | unsigned | pos | ) |
Inserts a gate into the circuit.
This method inserts a gate at an arbitrary position in the circuit
pos | Position where to insert the gate |
bool is_subcircuit | ( | ) | const |
Returns whether the circuit is a sub-circuit or not.
Both standard_circuit and subcircuit are used in the context as a circuit in other algorithms. To determine what kind of circuit it is, this method returns true
if the circuit is a sub-circuit, false
otherwise.
false
otherwiseunsigned lines | ( | ) | const |
Returns the number of lines.
This method returns the number of lines.
const std::map<std::string, boost::shared_ptr<circuit> >& modules | ( | ) | const |
Returns all modules in the circuit.
This method returns a map of all modules, whereby the keys are the names of the modules.
unsigned num_gates | ( | ) | const |
Returns the number of gates.
This method returns the number of gates in the circuit.
unsigned offset | ( | ) | const |
Returns the offset of the circuit (sub-circuit)
For a standard_circuit, the offset is always 0, but for a sub-circuit, the offset is the index of the starting gate in respect to its base circuit.
const gate& operator[] | ( | unsigned | index | ) | const |
Random access operator for access to gates by index.
index | Index of the gate, starting from 0 |
index
gate in the circuitgate& operator[] | ( | unsigned | index | ) |
Random access operator for access to gates by index.
index | Index of the gate, starting from 0 |
index
gate in the circuitconst bus_collection& outputbuses | ( | ) | const |
Constant access to the output buses.
This method gives constant access to the output buses.
bus_collection& outputbuses | ( | ) |
Mutable access to the output buses.
This method gives mutable access to the output buses.
const std::vector<std::string>& outputs | ( | ) | const |
Returns the output names of the lines in a circuit.
This method returns the output names of the lines in a circuit. This is useful for functions when writing them to a file, printing them, or creating images.
gate& prepend_gate | ( | ) |
Inserts a gate at the beginning of the circuit.
This method inserts a gate at the beginning of the circuit.
const_reverse_iterator rbegin | ( | ) | const |
Constant begin reverse iterator pointing to gates.
reverse_iterator rbegin | ( | ) |
Mutable begin reverse iterator pointing to gates.
void remove_gate_at | ( | unsigned | pos | ) |
Removes a gate at a given index.
If the index is not valid, no gate is removed.
pos | Index |
const_reverse_iterator rend | ( | ) | const |
Constant end reverse iterator pointing to gates.
reverse_iterator rend | ( | ) |
Mutable end reverse iterator pointing to gates.
void set_circuit_name | ( | const std::string & | name | ) |
Sets a name of the circuit.
Sets a name for the circuit which is empty initially.
name | Name |
void set_constants | ( | const std::vector< constant > & | constants | ) |
Sets the constant input line specifications.
This method sets the constant input line specification.
Lines are by default not constant. If less values are given than lines exist, the last ones will be not constant. If more values are given than lines exist, they will be truncated.
constants | Constant Lines |
void set_garbage | ( | const std::vector< bool > & | garbage | ) |
Sets whether outputs are garbage or not.
If an output is garbage it means, that the resulting output value is not necessary for the function.
Lines are by default not garbage. If less values are given than lines exist, the last ones will be not garbage. If more values are given than lines exist, they will be truncated.
garbage | Garbage line specification |
void set_inputs | ( | const std::vector< std::string > & | inputs | ) |
Sets the input names of the lines in a circuit.
This method sets the input names of the lines in a circuit. This is useful for functions when writing them to a file, printing them, or creating images.
inputs | Input names |
void set_lines | ( | unsigned | lines | ) |
Sets the number of line.
This method sets the number of lines of the circuit.
Changing this number will not affect the data in the gates. For example: If there is a gate with a control on line 3, and the number of lines is reduced to 2 in the circuit, then the control is still on line 3 but not visible in this circuit.
So, changing the lines after already adding gates can lead to invalid gates.
lines | Number of lines |
void set_outputs | ( | const std::vector< std::string > & | outputs | ) |
Sets the output names of the lines in a circuit.
This method sets the output names of the lines in a circuit. This is useful for functions when writing them to a file, printing them, or creating images.
outputs | Output names |
const bus_collection& statesignals | ( | ) | const |
Constant access to the state signals.
This method gives constant access to the state signals.
bus_collection& statesignals | ( | ) |
Mutable access to the state signals.
This method gives mutable access to the state signals.
boost::signal<void(gate&)> gate_added |
Signal which is emitted after adding a gate.
The gate is always empty, since when adding a gate to the circuit an empty gate is returned as reference and then further processed by functions such as append_toffoli.