Skip to content

Commit

Permalink
Many mentions to QASM should be changed to OpenQASM 2 (#9351)
Browse files Browse the repository at this point in the history
* Many mentions to QASM should be changed to OpenQASM2

* adjust tests

* another round

* suggestion in https://github.com/Qiskit/qiskit-terra/pull/9351/files#r1068676297

* https://github.com/Qiskit/qiskit-terra/pull/9351/files#r1068704441

* Normalise spacing of OpenQASM [23]

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
  • Loading branch information
1ucian0 and jakelishman authored Sep 29, 2023
1 parent a4ca0ca commit c6c9267
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion qiskit/algorithms/optimizers/spsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SPSA(Optimizer):
SPSA can be used in the presence of noise, and it is therefore indicated in situations
involving measurement uncertainty on a quantum computation when finding a minimum.
If you are executing a variational algorithm using a Quantum ASseMbly Language (QASM)
If you are executing a variational algorithm using an OpenQASM
simulator or a real device, SPSA would be the most recommended choice among the optimizers
provided here.
Expand Down
4 changes: 2 additions & 2 deletions qiskit/assembler/assemble_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _assemble_circuit(
if calibrations:
config.calibrations = calibrations

# Convert conditionals from QASM-style (creg ?= int) to qobj-style
# Convert conditionals from OpenQASM-2-style (creg ?= int) to qobj-style
# (register_bit ?= 1), by assuming device has unlimited register slots
# (supported only for simulators). Map all measures to a register matching
# their clbit_index, create a new register slot for every conditional gate
Expand Down Expand Up @@ -213,7 +213,7 @@ def _extract_common_calibrations(
and delete them from their local experiments.
Args:
experiments: The list of Qasm experiments that are being assembled into one qobj
experiments: The list of OpenQASM experiments that are being assembled into one qobj
Returns:
The input experiments with modified calibrations, and common calibrations, if there
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/controlflow/for_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def params(self, parameters):
)

# Consume indexset into a tuple unless it was provided as a range.
# Preserve ranges so that they can be exported as OpenQASM3 ranges.
# Preserve ranges so that they can be exported as OpenQASM 3 ranges.
indexset = indexset if isinstance(indexset, range) else tuple(indexset)

self._params = [indexset, loop_parameter, body]
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/hamiltonian_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _define(self):
)
def qasm(self):
"""Raise an error, as QASM is not defined for the HamiltonianGate."""
raise CircuitError("HamiltonianGate has no QASM definition.")
raise CircuitError("HamiltonianGate has no OpenQASM 2 definition.")

def validate_parameter(self, parameter):
"""Hamiltonian parameter has to be an ndarray, operator or float."""
Expand Down
19 changes: 10 additions & 9 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,8 +1608,8 @@ def qasm(
interface for other serialisers in Qiskit.
Args:
formatted (bool): Return formatted Qasm string.
filename (str): Save Qasm to file with name 'filename'.
formatted (bool): Return formatted OpenQASM 2.0 string.
filename (str): Save OpenQASM 2.0 to file with name 'filename'.
encoding (str): Optionally specify the encoding to use for the
output file if ``filename`` is specified. By default this is
set to the system's default encoding (ie whatever
Expand All @@ -1634,7 +1634,7 @@ def qasm(
print(out, file=file)

if formatted:
_optionals.HAS_PYGMENTS.require_now("formatted OpenQASM 2 output")
_optionals.HAS_PYGMENTS.require_now("formatted OpenQASM 2.0 output")

import pygments
from pygments.formatters import ( # pylint: disable=no-name-in-module
Expand Down Expand Up @@ -2390,13 +2390,14 @@ def remove_final_measurements(self, inplace: bool = True) -> Optional["QuantumCi

@staticmethod
def from_qasm_file(path: str) -> "QuantumCircuit":
"""Take in a QASM file and generate a QuantumCircuit object.
"""Read an OpenQASM 2.0 program from a file and convert to an instance of
:class:`.QuantumCircuit`.
Args:
path (str): Path to the file for a QASM program
path (str): Path to the file for an OpenQASM 2 program
Return:
QuantumCircuit: The QuantumCircuit object for the input QASM
QuantumCircuit: The QuantumCircuit object for the input OpenQASM 2.
See also:
:func:`.qasm2.load`: the complete interface to the OpenQASM 2 importer.
Expand All @@ -2414,12 +2415,12 @@ def from_qasm_file(path: str) -> "QuantumCircuit":

@staticmethod
def from_qasm_str(qasm_str: str) -> "QuantumCircuit":
"""Take in a QASM string and generate a QuantumCircuit object.
"""Convert a string containing an OpenQASM 2.0 program to a :class:`.QuantumCircuit`.
Args:
qasm_str (str): A QASM program string
qasm_str (str): A string containing an OpenQASM 2.0 program.
Return:
QuantumCircuit: The QuantumCircuit object for the input QASM
QuantumCircuit: The QuantumCircuit object for the input OpenQASM 2
See also:
:func:`.qasm2.loads`: the complete interface to the OpenQASM 2 importer.
Expand Down
4 changes: 2 additions & 2 deletions qiskit/compiler/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def assemble(
``n_qubits.``
schedule_los: Experiment level (ie circuit or schedule) LO frequency configurations for
qubit drive and measurement channels. These values override the job level values from
``default_qubit_los`` and ``default_meas_los``. Frequencies are in Hz. Settable for qasm
and pulse jobs.
``default_qubit_los`` and ``default_meas_los``. Frequencies are in Hz. Settable for
OpenQASM 2 and pulse jobs.
meas_level: Set the appropriate level of the measurement output for pulse experiments.
meas_return: Level of measurement data for the backend to return.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/converters/ast_to_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def _process_node(self, node):
return None

def _gate_rules_to_qiskit_circuit(self, node, params):
"""From a gate definition in qasm, to a QuantumCircuit format."""
"""From a gate definition in OpenQASM, to a QuantumCircuit format."""
rules = []
qreg = QuantumRegister(node["n_bits"])
bit_args = {node["bits"][i]: q for i, q in enumerate(qreg)}
Expand Down
4 changes: 2 additions & 2 deletions qiskit/providers/basicaer/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

"""Contains a (slow) Python simulator.
It simulates a qasm quantum circuit (an experiment) that has been compiled
It simulates an OpenQASM 2 quantum circuit (an experiment) that has been compiled
to run on the simulator. It is exponential in the number of qubits.
The simulator is run using
Expand Down Expand Up @@ -53,7 +53,7 @@


class QasmSimulatorPy(BackendV1):
"""Python implementation of a qasm simulator."""
"""Python implementation of an OpenQASM 2 simulator."""

MAX_QUBITS_MEMORY = int(log2(local_hardware_info()["memory"] * (1024**3) / 16))

Expand Down
2 changes: 1 addition & 1 deletion qiskit/providers/fake_provider/fake_qasm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


class FakeQasmBackend(FakeBackend):
"""A fake qasm backend."""
"""A fake OpenQASM backend."""

dirname = None
conf_filename = None
Expand Down
2 changes: 1 addition & 1 deletion qiskit/providers/fake_provider/fake_qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# that they have been altered from the originals.

"""
Fake qasm simulator.
Fake OpenQASM simulator.
"""

from qiskit.providers.models import GateConfig, QasmBackendConfiguration
Expand Down
11 changes: 5 additions & 6 deletions qiskit/providers/models/backendconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class GateConfig:
"""Class representing a Gate Configuration
Attributes:
name: the gate name as it will be referred to in Qasm.
name: the gate name as it will be referred to in OpenQASM.
parameters: variable names for the gate parameters (if any).
qasm_def: definition of this gate in terms of Qasm primitives U
qasm_def: definition of this gate in terms of OpenQASM 2 primitives U
and CX.
"""

Expand All @@ -51,11 +51,10 @@ def __init__(
"""Initialize a GateConfig object
Args:
name (str): the gate name as it will be referred to in Qasm.
name (str): the gate name as it will be referred to in OpenQASM.
parameters (list): variable names for the gate parameters (if any)
as a list of strings.
qasm_def (str): definition of this gate in terms of Qasm primitives
U and CX.
qasm_def (str): definition of this gate in terms of OpenQASM 2 primitives U and CX.
coupling_map (list): An optional coupling map for the gate. In
the form of a list of lists of integers representing the qubit
groupings which are coupled by this gate.
Expand Down Expand Up @@ -194,7 +193,7 @@ def __repr__(self):


class QasmBackendConfiguration:
"""Class representing a Qasm Backend Configuration.
"""Class representing an OpenQASM 2.0 Backend Configuration.
Attributes:
backend_name: backend name.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/qasm/node/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""QASM nodes."""
"""OpenQASM 2 nodes."""

from .barrier import Barrier
from .binaryop import BinaryOp
Expand Down
2 changes: 1 addition & 1 deletion qiskit/qasm/node/binaryoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ def operation(self):
raise NodeException(f"internal error: undefined operator '{self.value}'") from ex

def qasm(self):
"""Return the QASM representation."""
"""Return the OpenQASM 2 representation."""
return self.value
6 changes: 3 additions & 3 deletions qiskit/qasm/node/unaryoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Node for an OPENQASM unary operator."""
"""Node for an OpenQASM 2 unary operator."""

import operator

Expand All @@ -25,7 +25,7 @@


class UnaryOperator(Node):
"""Node for an OPENQASM unary operator.
"""Node for an OpenQASM 2 unary operator.
This node has no children. The data is in the value field.
"""
Expand All @@ -45,5 +45,5 @@ def operation(self):
raise NodeException(f"internal error: undefined prefix '{self.value}'") from ex

def qasm(self):
"""Return QASM representation."""
"""Return OpenQASM 2 representation."""
return self.value
2 changes: 1 addition & 1 deletion qiskit/qasm/qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, filename=None, data=None):
if filename is None and data is None:
raise QasmError("Missing input file and/or data")
if filename is not None and data is not None:
raise QasmError("File and data must not both be specified initializing qasm")
raise QasmError("File and data must not both be specified initializing OpenQASM 2")
self._filename = filename
self._data = data

Expand Down
10 changes: 5 additions & 5 deletions qiskit/qasm3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,25 @@


def dumps(circuit, **kwargs) -> str:
"""Serialize a :class:`~qiskit.circuit.QuantumCircuit` object in an OpenQASM3 string.
"""Serialize a :class:`~qiskit.circuit.QuantumCircuit` object in an OpenQASM 3 string.
Args:
circuit (QuantumCircuit): Circuit to serialize.
**kwargs: Arguments for the :obj:`.Exporter` constructor.
Returns:
str: The OpenQASM3 serialization
str: The OpenQASM 3 serialization
"""
return Exporter(**kwargs).dumps(circuit)


def dump(circuit, stream, **kwargs) -> None:
"""Serialize a :class:`~qiskit.circuit.QuantumCircuit` object as a OpenQASM3 stream to file-like
object.
"""Serialize a :class:`~qiskit.circuit.QuantumCircuit` object as an OpenQASM 3 stream to
file-like object.
Args:
circuit (QuantumCircuit): Circuit to serialize.
stream (TextIOBase): stream-like object to dump the OpenQASM3 serialization
stream (TextIOBase): stream-like object to dump the OpenQASM 3 serialization
**kwargs: Arguments for the :obj:`.Exporter` constructor.
"""
Expand Down
10 changes: 5 additions & 5 deletions qiskit/qasm3/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(
basis_gates: the basic defined gate set of the backend.
disable_constants: if ``True``, always emit floating-point constants for numeric
parameter values. If ``False`` (the default), then values close to multiples of
QASM 3 constants (``pi``, ``euler``, and ``tau``) will be emitted in terms of those
OpenQASM 3 constants (``pi``, ``euler``, and ``tau``) will be emitted in terms of those
constants instead, potentially improving accuracy in the output.
alias_classical_registers: If ``True``, then bits may be contained in more than one
register. If so, the registers will be emitted using "alias" definitions, which
Expand Down Expand Up @@ -176,13 +176,13 @@ def __init__(
self.experimental = experimental

def dumps(self, circuit):
"""Convert the circuit to QASM 3, returning the result as a string."""
"""Convert the circuit to OpenQASM 3, returning the result as a string."""
with io.StringIO() as stream:
self.dump(circuit, stream)
return stream.getvalue()

def dump(self, circuit, stream):
"""Convert the circuit to QASM 3, dumping the result to a file or text stream."""
"""Convert the circuit to OpenQASM 3, dumping the result to a file or text stream."""
builder = QASM3Builder(
circuit,
includeslist=self.includes,
Expand Down Expand Up @@ -888,7 +888,7 @@ def build_for_loop(self, instruction: CircuitInstruction) -> ast.ForLoopStatemen
else:
loop_parameter_ast = self._register_variable(loop_parameter, scope)
if isinstance(indexset, range):
# QASM 3 uses inclusive ranges on both ends, unlike Python.
# OpenQASM 3 uses inclusive ranges on both ends, unlike Python.
indexset_ast = ast.Range(
start=self.build_integer(indexset.start),
end=self.build_integer(indexset.stop - 1),
Expand All @@ -899,7 +899,7 @@ def build_for_loop(self, instruction: CircuitInstruction) -> ast.ForLoopStatemen
indexset_ast = ast.IndexSet([self.build_integer(value) for value in indexset])
except QASM3ExporterError:
raise QASM3ExporterError(
"The values in QASM 3 'for' loops must all be integers, but received"
"The values in OpenQASM 3 'for' loops must all be integers, but received"
f" '{indexset}'."
) from None
body_ast = self.build_program_block(loop_circuit)
Expand Down
6 changes: 3 additions & 3 deletions qiskit/qasm3/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Printers for QASM 3 AST nodes."""
"""Printers for OpenQASM 3 AST nodes."""

import collections
import io
Expand Down Expand Up @@ -60,7 +60,7 @@


class BasicPrinter:
"""A QASM 3 AST visitor which writes the tree out in text mode to a stream, where the only
"""An OpenQASM 3 AST visitor which writes the tree out in text mode to a stream, where the only
formatting is simple block indentation."""

_CONSTANT_LOOKUP = {
Expand Down Expand Up @@ -134,7 +134,7 @@ def visit(self, node: ast.ASTNode) -> None:
however, if you want to build up a file bit-by-bit manually.
Args:
node (ASTNode): the node to convert to QASM 3 and write out to the stream.
node (ASTNode): the node to convert to OpenQASM 3 and write out to the stream.
Raises:
RuntimeError: if an AST node is encountered that the visitor is unable to parse. This
Expand Down
2 changes: 1 addition & 1 deletion qiskit/qobj/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, **kwargs):
self.__dict__.update(kwargs)

def to_dict(self):
"""Return a dictionary format representation of the QASM Qobj.
"""Return a dictionary format representation of the OpenQASM 2 Qobj.
Returns:
dict: The dictionary form of the QobjHeader.
Expand Down
Loading

0 comments on commit c6c9267

Please sign in to comment.