qoqo.Circuit
- class qoqo.Circuit
Circuit of Operations.
A quantum program is represented as a linear sequence of Operations.
- __init__()
Methods
__init__
()add
(op)Add an Operation to Circuit.
count_occurences
(operations)Count the number of occurences of a set of operation tags in the circuit.
Returns the current version of the qoqo library .
Return a list of definitions in the Circuit.
filter_by_tag
(tag)Return a list of operations with given tag.
from_bincode
(input)Convert the bincode representation of the Circuit to a Circuit using the [bincode] crate.
from_json
(json_string)Convert the json representation of a Circuit to a Circuit.
get
(index)Return a copy of the Operation at a certain index of the Circuit.
Return a list of the hqslang names of all operations occuring in the circuit.
get_slice
([start, stop])Return the copy of a slice of the Circuit.
Return the JsonSchema for the json serialisation of the class.
Return the minimum version of qoqo that supports this object.
Return a list of all operations in the Circuit.
Return clone of the circuit with all overrotation Pragmas applied.
remap_qubits
(mapping)Remap qubits in operations in clone of Circuit.
substitute_parameters
(substitution_parameters)Substitute the symbolic parameters in a clone of the Circuit according to the substitution_parameters input.
Return the bincode representation of the Circuit using the [bincode] crate.
to_json
()Return the json representation of the Circuit.
- add(op)
Add an Operation to Circuit.
- Parameters:
op (Operation) -- The Operation to add to the Circuit.
- count_occurences(operations)
Count the number of occurences of a set of operation tags in the circuit.
- Parameters:
operations (List[str]) -- List of operation tags that should be counted.
- Returns:
The number of occurences of these operation tags.
- Return type:
int
- static current_version()
Returns the current version of the qoqo library .
- Returns:
The current version of the library.
- Return type:
str
- definitions()
Return a list of definitions in the Circuit.
Definitions need to be unique.
- Returns:
A vector of the definitions in the Circuit.
- Return type:
List[Operation]
- filter_by_tag(tag)
Return a list of operations with given tag.
- Parameters:
tag (str) -- tag by which to filter operations.
- Returns:
A vector of the operations with the specified tag in the Circuit.
- Return type:
List[Operation]
- static from_bincode(input)
Convert the bincode representation of the Circuit to a Circuit using the [bincode] crate.
- Parameters:
input (ByteArray) -- The serialized Circuit (in [bincode] form).
- Returns:
The deserialized Circuit.
- Return type:
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized to Circuit.
- static from_json(json_string)
Convert the json representation of a Circuit to a Circuit.
- Parameters:
input (str) -- The serialized Circuit in json form.
- Returns:
The deserialized Circuit.
- Return type:
- Raises:
ValueError -- Input cannot be deserialized to Circuit.
- get(index)
Return a copy of the Operation at a certain index of the Circuit.
- Parameters:
index (int) -- The index of the Operation to get in the Circuit.
- Returns:
The operation at the given index (if it exists).
- Return type:
Operation
- Raises:
IndexError -- Index out of range.
- get_operation_types()
Return a list of the hqslang names of all operations occuring in the circuit.
- Returns:
The operation types in the Circuit.
- Return type:
Set[str]
- get_slice(start=None, stop=None)
Return the copy of a slice of the Circuit.
- Parameters:
start (Optional[int]) -- The starting index of the slice (inclusive).
stop (Optional[int]) -- The stopping index of the slice (exclusive).
- Returns:
The slice of the operations in the Circuit with the specified indices.
- Return type:
- Raises:
IndexError -- Stop index smaller than start index.
IndexError -- Stop index out of range.
IndexError -- Start index out of range.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of qoqo that supports this object.
- Returns:
The minimum version of the qoqo library to deserialize this object.
- Return type:
str
- operations()
Return a list of all operations in the Circuit.
- Returns:
A vector of the operations in the Circuit.
- Return type:
List[Operation]
- overrotate()
Return clone of the circuit with all overrotation Pragmas applied.
- Returns:
Circuit with the overrotation applied
- Return type:
- Raises:
RuntimeError -- Error applying PragmaOverrotation in circuit.
Example:
>>> circuit = Circuit() >>> circuit += PragmaOverrotation("RotateY", [1,], 20.0, 30.0) >>> circuit += RotateX(0, 0.0) >>> circuit += RotateY(0, 1.0) >>> circuit += RotateY(1, 2.0) >>> circuit += RotateY(1, 3.0) >>> circuit_overrotated = circuit.overrotate() print(circuit) print(circuit_overrotated)
- remap_qubits(mapping)
Remap qubits in operations in clone of Circuit.
- Parameters:
mapping (Dict[int, int]) -- The dictionary containing the {qubit: qubit} mapping to use in the Circuit.
- Returns:
The Circuit with the qubits remapped.
- Return type:
self
- Raises:
RuntimeError -- The qubit remapping failed.
- substitute_parameters(substitution_parameters)
Substitute the symbolic parameters in a clone of the Circuit according to the substitution_parameters input.
- Parameters:
substitution_parameters (Dict[str, float]) -- The dictionary containing the substitutions to use in the Circuit.
- Returns:
The Circuit with the parameters substituted.
- Return type:
self
- Raises:
RuntimeError -- The parameter substitution failed.
- to_bincode()
Return the bincode representation of the Circuit using the [bincode] crate.
- Returns:
The serialized Circuit (in [bincode] form).
- Return type:
ByteArray
- Raises:
ValueError -- Cannot serialize Circuit to bytes.
- to_json()
Return the json representation of the Circuit.
- Returns:
The serialized form of Circuit.
- Return type:
str
- Raises:
ValueError -- Cannot serialize Circuit to json.