Skip to content

Added example for configuration format #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions docs/request/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,107 @@ This message does not require any additional information in the payload section.
}
```

###### Example of default_compiler_config

```python
import importlib
from opensquirrel.decomposer.cnot_decomposer import CNOTDecomposer
from opensquirrel.circuit import Circuit
from opensquirrel.decomposer.aba_decomposer import XYXDecomposer

circuit = """\
version 3.0

qubit[3] q
bit[3] b

H q[1]
CZ q[0], q[1]
CNOT q[0], q[1]
CRk(4) q[0], q[1]
H q[0]
b[1:2] = measure q[0:1]
"""

def backend_hardcoded(circuit: str) -> None:
# Decompose 2-qubit gates to a decomposition where the 2-qubit interactions are captured by CNOT gates
qc.decompose(decomposer=CNOTDecomposer())

# This statement will be replaced by somelike qc.decompose(CNOTTOCZ())
qc.replace(
CNOT,
lambda control, target: [
H(target),
CZ(control, target),
H(target),
],
)

# Merge single-qubit gates and decompose with McKay decomposition.
qc.merge_single_qubit_gates()
qc.decompose(decomposer=McKayDecomposer())

def backend_configurable(circuit: str, compiler_config: Dict[str, List[Dict[str, Any]]]) -> str:
"""
Configures a quantum circuit for a specified backend by dynamically applying compiler stages
and passes from the given configuration.

Args:
circuit: The quantum circuit.
compiler_config: The configuration for the compilation process.

Example structure:

default_compiler_config = {
"decomposition": [
{
"path": "opensquirrel.decomposer.cnot_decomposer.CNOTDecomposer",
"method": "decompose",
"arguments": {
"merge_single_qubit_gates": None
}
},
{
"path": "opensquirrel.decomposer.cnot_to_cz_decomposer.CNOTTOCZ",
"method": "decompose",
"arguments": {
"merge_single_qubit_gates": None
}
},
{
"path": "opensquirrel.decomposer.aba_decomposer.XYXDecomposer",
"method": "decompose",
"arguments": {
"merge_single_qubit_gates": True
}
}
],
}

- "decomposition": A key representing the name of (one of) the compilation stage. And its value is a list of compiler passes.
Each compiler pass has
- "path": Specifies the import path of the opensquirrel object that does the compiler pass.
- "method": Specifies the method (e.g., "decompose") on the opensquirrel object that does the compiler pass.
- "arguments": Contains parameters for compiler pass.

Returns:
str: The compiled circuit with passes applied to it
"""
qc = Circuit.from_string(circuit)

for stage, passes in compiler_config.items():
for _pass in passes:
mod_name, class_name = _pass["path"].rsplit(".", 1)
module = importlib.import_module(mod_name)
quantum_operator = getattr(module, class_name) # Maps to the specified decomposer class
method = _pass["method"] # Maps to the method (qc.decompose)

# Passes arguments to the operator instance
arguments = _pass["arguments"]
getattr(qc, method)(quantum_operator(**arguments))
return str(qc)
```

#### Get dynamic

Dynamic information is generated by 2300. This information can for example constitute calibration data like T1 and T2*.
Expand Down
Loading