mimiqcircuits.qasm.serializer¶
Functions
|
|
|
|
|
|
|
Write a circuit as an OpenQASM 2.0 program to a file. |
|
Write a circuit as an OpenQASM 2.0 program. |
|
|
|
|
|
|
|
|
|
|
|
- dumps(c, decompose_wrappers=False, sanitize_names=True)[source]¶
Write a circuit as an OpenQASM 2.0 program.
Operations that OpenQASM 2.0 cannot express directly are decomposed into
qelib1.incgates, and gate declarations (GateDecl) becomegatedefinitions. All qubits go in one registerqand all bits in one registerc.- Parameters:
- Returns:
The OpenQASM 2.0 source.
- Return type:
- Raises:
DecompositionError – If an operation cannot be decomposed into the OpenQASM 2.0 basis, such as a noise channel or a classical or z-variable operation.
QASMSerializationError – If a name or an
IfStatementcondition cannot be expressed in OpenQASM 2.0.
Examples
>>> from mimiqcircuits import * >>> from mimiqcircuits import qasm >>> c = Circuit() >>> c.push(GateH(), 0) 1-qubit circuit with 1 instruction: └── H @ q[0] >>> c.push(GateCX(), 0, 1) 2-qubit circuit with 2 instructions: ├── H @ q[0] └── CX @ q[0], q[1] >>> c.push(Measure(), range(2), range(2)) 2-qubit, 2-bit circuit with 4 instructions: ├── H @ q[0] ├── CX @ q[0], q[1] ├── M @ q[0], c[0] └── M @ q[1], c[1] >>> print(qasm.dumps(c)) OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; creg c[2]; h q[0]; cx q[0],q[1]; measure q[0] -> c[0]; measure q[1] -> c[1];
- dump(c, filename, decompose_wrappers=False, sanitize_names=True)[source]¶
Write a circuit as an OpenQASM 2.0 program to a file.
The file is overwritten, unless serialization fails. See
dumps()for how the circuit is written;load()reads the file back.- Parameters:
- Raises:
DecompositionError – If an operation cannot be decomposed into the OpenQASM 2.0 basis.
QASMSerializationError – If a name or an
IfStatementcondition cannot be expressed in OpenQASM 2.0.