Skip to content

Commit

Permalink
Add rotation gates to unitary simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseclectic committed Sep 8, 2020
1 parent 0ac7c35 commit da692e1
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 356 deletions.
264 changes: 45 additions & 219 deletions qiskit/providers/aer/backends/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# that they have been altered from the originals.

# pylint: disable=invalid-name

"""
Qiskit Aer Unitary Simulator Backend.
"""
Expand Down Expand Up @@ -75,225 +74,52 @@ class UnitarySimulator(AerBackend):
performance (Default: 14).
"""

MAX_QUBIT_MEMORY = int(log2(sqrt(local_hardware_info()['memory'] * (1024 ** 3) / 16)))
MAX_QUBIT_MEMORY = int(
log2(sqrt(local_hardware_info()['memory'] * (1024**3) / 16)))

DEFAULT_CONFIGURATION = {
'backend_name': 'unitary_simulator',
'backend_version': __version__,
'n_qubits': MAX_QUBIT_MEMORY,
'url': 'https://github.com/Qiskit/qiskit-aer',
'simulator': True,
'local': True,
'conditional': False,
'open_pulse': False,
'memory': False,
'max_shots': int(1e6), # Note that this backend will only ever
# perform a single shot. This value is just
# so that the default shot value for execute
# will not raise an error when trying to run
# a simulation
'description': 'A C++ unitary simulator for QASM Qobj files',
'coupling_map': None,
'backend_name':
'unitary_simulator',
'backend_version':
__version__,
'n_qubits':
MAX_QUBIT_MEMORY,
'url':
'https://github.com/Qiskit/qiskit-aer',
'simulator':
True,
'local':
True,
'conditional':
False,
'open_pulse':
False,
'memory':
False,
'max_shots':
int(1e6), # Note that this backend will only ever
# perform a single shot. This value is just
# so that the default shot value for execute
# will not raise an error when trying to run
# a simulation
'description':
'A C++ unitary simulator for QASM Qobj files',
'coupling_map':
None,
'basis_gates': [
'u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', 'h', 's', 'sdg',
't', 'tdg', 'swap', 'ccx', 'unitary', 'diagonal', 'cu1', 'cu2',
'cu3', 'cswap', 'mcx', 'mcy', 'mcz', 'mcu1', 'mcu2', 'mcu3',
'mcswap', 'multiplexer',
't', 'tdg', 'swap', 'ccx', 'r', 'rx', 'ry', 'rz', 'rxx', 'ryy',
'rzz', 'rzx', 'unitary', 'diagonal', 'cu1', 'cu2',
'cu3', 'cswap', 'mcx', 'mcy', 'mcz', 'mcrx', 'mcry', 'mcrz', 'mcr',
'mcu1', 'mcu2', 'mcu3', 'mcswap', 'multiplexer', 'kraus', 'roerror'
],
'gates': [{
'name': 'u1',
'parameters': ['lam'],
'conditional': True,
'description': 'Single-qubit gate [[1, 0], [0, exp(1j*lam)]]',
'qasm_def': 'gate u1(lam) q { U(0,0,lam) q; }'
}, {
'name': 'u2',
'parameters': ['phi', 'lam'],
'conditional': True,
'description':
'Single-qubit gate [[1, -exp(1j*lam)], [exp(1j*phi), exp(1j*(phi+lam))]]/sqrt(2)',
'qasm_def': 'gate u2(phi,lam) q { U(pi/2,phi,lam) q; }'
}, {
'name':
'u3',
'parameters': ['theta', 'phi', 'lam'],
'conditional':
True,
'description':
'Single-qubit gate with three rotation angles',
'qasm_def':
'gate u3(theta,phi,lam) q { U(theta,phi,lam) q; }'
}, {
'name': 'cx',
'parameters': [],
'conditional': True,
'description': 'Two-qubit Controlled-NOT gate',
'qasm_def': 'gate cx c,t { CX c,t; }'
}, {
'name': 'cz',
'parameters': [],
'conditional': True,
'description': 'Two-qubit Controlled-Z gate',
'qasm_def': 'gate cz a,b { h b; cx a,b; h b; }'
}, {
'name': 'id',
'parameters': [],
'conditional': True,
'description': 'Single-qubit identity gate',
'qasm_def': 'gate id a { U(0,0,0) a; }'
}, {
'name': 'x',
'parameters': [],
'conditional': True,
'description': 'Single-qubit Pauli-X gate',
'qasm_def': 'gate x a { U(pi,0,pi) a; }'
}, {
'name': 'y',
'parameters': [],
'conditional': True,
'description': 'Single-qubit Pauli-Y gate',
'qasm_def': 'TODO'
}, {
'name': 'z',
'parameters': [],
'conditional': True,
'description': 'Single-qubit Pauli-Z gate',
'qasm_def': 'TODO'
}, {
'name': 'h',
'parameters': [],
'conditional': True,
'description': 'Single-qubit Hadamard gate',
'qasm_def': 'TODO'
}, {
'name': 's',
'parameters': [],
'conditional': True,
'description': 'Single-qubit phase gate',
'qasm_def': 'TODO'
}, {
'name': 'sdg',
'parameters': [],
'conditional': True,
'description': 'Single-qubit adjoint phase gate',
'qasm_def': 'TODO'
}, {
'name': 't',
'parameters': [],
'conditional': True,
'description': 'Single-qubit T gate',
'qasm_def': 'TODO'
}, {
'name': 'tdg',
'parameters': [],
'conditional': True,
'description': 'Single-qubit adjoint T gate',
'qasm_def': 'TODO'
}, {
'name': 'swap',
'parameters': [],
'conditional': True,
'description': 'Two-qubit SWAP gate',
'qasm_def': 'TODO'
}, {
'name': 'ccx',
'parameters': [],
'conditional': True,
'description': 'Three-qubit Toffoli gate',
'qasm_def': 'TODO'
}, {
'name': 'cswap',
'parameters': [],
'conditional': True,
'description': 'Three-qubit Fredkin (controlled-SWAP) gate',
'qasm_def': 'TODO'
}, {
'name': 'unitary',
'parameters': ['matrix'],
'conditional': True,
'description': 'N-qubit arbitrary unitary gate. '
'The parameter is the N-qubit matrix to apply.',
'qasm_def': 'unitary(matrix) q1, q2,...'
}, {
'name': 'diagonal',
'parameters': ['diag_elements'],
'conditional': True,
'description': 'N-qubit diagonal unitary gate. The parameters are the'
' diagonal entries of the N-qubit matrix to apply.',
'qasm_def': 'TODO'
}, {
'name': 'cu1',
'parameters': ['lam'],
'conditional': True,
'description': 'Two-qubit Controlled-u1 gate',
'qasm_def': 'TODO'
}, {
'name': 'cu2',
'parameters': ['phi', 'lam'],
'conditional': True,
'description': 'Two-qubit Controlled-u2 gate',
'qasm_def': 'TODO'
}, {
'name': 'cu3',
'parameters': ['theta', 'phi', 'lam'],
'conditional': True,
'description': 'Two-qubit Controlled-u3 gate',
'qasm_def': 'TODO'
}, {
'name': 'mcx',
'parameters': [],
'conditional': True,
'description': 'N-qubit multi-controlled-X gate',
'qasm_def': 'TODO'
}, {
'name': 'mcy',
'parameters': [],
'conditional': True,
'description': 'N-qubit multi-controlled-Y gate',
'qasm_def': 'TODO'
}, {
'name': 'mcz',
'parameters': [],
'conditional': True,
'description': 'N-qubit multi-controlled-Z gate',
'qasm_def': 'TODO'
}, {
'name': 'mcu1',
'parameters': ['lam'],
'conditional': True,
'description': 'N-qubit multi-controlled-u1 gate',
'qasm_def': 'TODO'
}, {
'name': 'mcu2',
'parameters': ['phi', 'lam'],
'conditional': True,
'description': 'N-qubit multi-controlled-u2 gate',
'qasm_def': 'TODO'
}, {
'name': 'mcu3',
'parameters': ['theta', 'phi', 'lam'],
'conditional': True,
'description': 'N-qubit multi-controlled-u3 gate',
'qasm_def': 'TODO'
}, {
'name': 'mcswap',
'parameters': [],
'conditional': True,
'description': 'N-qubit multi-controlled-SWAP gate',
'qasm_def': 'TODO'
}, {
'name': 'multiplexer',
'parameters': ['mat1', 'mat2', '...'],
'conditional': True,
'description': 'N-qubit multi-plexer gate. '
'The input parameters are the gates for each value.',
'qasm_def': 'TODO'
}]
'gates': []
}

def __init__(self, configuration=None, provider=None):
super().__init__(unitary_controller_execute,
QasmBackendConfiguration.from_dict(self.DEFAULT_CONFIGURATION),
QasmBackendConfiguration.from_dict(
self.DEFAULT_CONFIGURATION),
provider=provider)

def _validate(self, qobj, backend_options, noise_model):
Expand All @@ -312,20 +138,20 @@ def _validate(self, qobj, backend_options, noise_model):
if n_qubits > max_qubits:
raise AerError(
'Number of qubits ({}) is greater than max ({}) for "{}" with {} GB system memory.'
.format(n_qubits, max_qubits, name, int(local_hardware_info()['memory'])))
.format(n_qubits, max_qubits, name,
int(local_hardware_info()['memory'])))
if qobj.config.shots != 1:
logger.info('"%s" only supports 1 shot. Setting shots=1.',
name)
logger.info('"%s" only supports 1 shot. Setting shots=1.', name)
qobj.config.shots = 1
for experiment in qobj.experiments:
exp_name = experiment.header.name
if getattr(experiment.config, 'shots', 1) != 1:
logger.info('"%s" only supports 1 shot. '
'Setting shots=1 for circuit "%s".',
name, exp_name)
logger.info(
'"%s" only supports 1 shot. '
'Setting shots=1 for circuit "%s".', name, exp_name)
experiment.config.shots = 1
for operation in experiment.instructions:
if operation.name in ['measure', 'reset']:
raise AerError(
'Unsupported {} instruction {} in circuit {}'
.format(name, operation.name, exp_name))
'Unsupported {} instruction {} in circuit {}'.format(
name, operation.name, exp_name))
Loading

0 comments on commit da692e1

Please sign in to comment.