From 6b82fb9bfeacd9be0f2e1063ae4ed9ed32d28c5c Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Mon, 22 Jan 2024 14:01:08 +0000 Subject: [PATCH] Minor fixes for markdown code examples --- docs/build/interoperate-qiskit-qasm2.mdx | 3 ++- docs/build/interoperate-qiskit-qasm3.mdx | 13 ++++++++----- docs/transpile/common-parameters.mdx | 18 +++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/docs/build/interoperate-qiskit-qasm2.mdx b/docs/build/interoperate-qiskit-qasm2.mdx index 8695cd1f319..60d878e9b34 100644 --- a/docs/build/interoperate-qiskit-qasm2.mdx +++ b/docs/build/interoperate-qiskit-qasm2.mdx @@ -13,6 +13,7 @@ Qiskit provides some tools for converting between OpenQASM representations of qu Currently two high-level functions are available for importing from OpenQASM 2 into Qiskit. These functions are `qasm2.load()`, which takes a file name, and `qasm2.loads()`, which takes the program itself as a string. ```python +import qiskit.qasm2 qiskit.qasm2.load(filename, *, include_path=('.',), include_input_directory='append', custom_instructions=(), custom_classical=(), strict=False) ``` @@ -110,7 +111,7 @@ Use `qasm2.loads()` to import an OpenQASM 2 program as a string into a QuantumCi ```python import math -from qiskit.qasm2 +import qiskit.qasm2 program = ''' include "qelib1.inc"; diff --git a/docs/build/interoperate-qiskit-qasm3.mdx b/docs/build/interoperate-qiskit-qasm3.mdx index 9f8eec2c063..ec4c863919c 100644 --- a/docs/build/interoperate-qiskit-qasm3.mdx +++ b/docs/build/interoperate-qiskit-qasm3.mdx @@ -14,22 +14,25 @@ This function is still in the exploratory phase. Therefore, it is likely that t ## Import an OpenQASM 3 program into Qiskit +You must install the package `qiskit_qasm3_import ` to use this function. Install using the following command. + +```python +pip install qiskit-qasm3-import +``` + Currently two high-level functions are available for importing from OpenQASM 3 into Qiskit. These functions are `load()`, which takes a file name, and `loads()`, which takes the program itself as a string: ```python +import qiskit.qasm3 qiskit.qasm3.load(file_name) ``` ```python +import qiskit.qasm3 qiskit.qasm3.loads(program-string) ``` -You must install the package `qiskit_qasm3_import ` to use this function. For example: - -```python -pip install qiskit-qasm3-import -``` In this example, we define a quantum program using OpenQASM 3, and use `loads()` to directly convert it into a QuantumCircuit: diff --git a/docs/transpile/common-parameters.mdx b/docs/transpile/common-parameters.mdx index 7c72dd5cb5b..76739837d88 100644 --- a/docs/transpile/common-parameters.mdx +++ b/docs/transpile/common-parameters.mdx @@ -19,13 +19,17 @@ When the approximation degree is less than 1.0, circuits with one or two CX gate As an example, we generate a random 2-qubit `UnitaryGate` which will be synthesized in the initial stage. Setting the `approximation_degree` less than 1.0 might generate an approximate circuit. We must also specify the `basis_gates` to let the synthesis method know which gates it can use for the approximate synthesis. ```python - UU = random_unitary(4, seed=12345) - rand_U = UnitaryGate(UU) +from qiskit import QuantumCircuit, transpile +from qiskit.circuit.library import UnitaryGate +from qiskit.quantum_info import random_unitary - qc = QuantumCircuit(2) - qc.append(rand_U, range(2)) - approx_qc = transpile(qc, approximation_degree=0.85, basis_gates=["sx", "rz", "cx"]) - print(approx_qc.count_ops()["cx"]) +UU = random_unitary(4, seed=12345) +rand_U = UnitaryGate(UU) + +qc = QuantumCircuit(2) +qc.append(rand_U, range(2)) +approx_qc = transpile(qc, approximation_degree=0.85, basis_gates=["sx", "rz", "cx"]) +print(approx_qc.count_ops()["cx"]) ``` This yields an output of `2` because the approximation requires fewer CX gates. @@ -38,7 +42,7 @@ The seed transpiler argument sets the random seed for the stochastic parts of th Example: ```python - optimized_1 = transpile(qc, backend=backend, seed_transpiler=11, optimization_level=1) +optimized_1 = transpile(qc, seed_transpiler=11, optimization_level=1) ```