Skip to content

Commit

Permalink
Add test for unreleased Qiskit (Qiskit#1950)
Browse files Browse the repository at this point in the history
* add tests for unreleased Qiskit

* Update .github/workflows/tests.yml

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Scheduled test for latest Qiskit

* run latest Qiskit test at push

* fix test

* fix qiskit test again

* fix test case for runtime parameter binding

* remove on push/pull request from latest Qiskit unit test

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
  • Loading branch information
doichanj and mtreinish authored Oct 19, 2023
1 parent 6d141c0 commit e7afbfb
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,4 @@ jobs:
rm -rf qiskit_aer
stestr run --slowest
shell: bash

54 changes: 54 additions & 0 deletions .github/workflows/unit-tests-latest-qiskit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Unit Tests for latest Qiskit
on:
schedule:
- cron: '0 5 * * *'
concurrency:
group: ${{ github.repository }}-${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
unit-tests-latest-qiskit:
runs-on: ubuntu-latest
timeout-minutes: 60
env:
AER_THRUST_BACKEND: OMP
QISKIT_TEST_CAPTURE_STREAMS: 1
# Needed to suppress a warning in jupyter-core 5.x by eagerly migrating to
# a new internal interface that will be the default in jupyter-core 6.x.
# This variable should become redundant on release of jupyter-core 6.
JUPYTER_PLATFORM_DIRS: 1
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Pip cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-${{ matrix.python-version}}-pip-test-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version}}-pip-test-
${{ runner.os }}-${{ matrix.python-version}}-pip-
${{ runner.os }}-${{ matrix.python-version}}-
- name: Install Deps
run: |
python -m pip install -U -c constraints.txt -r requirements-dev.txt wheel
pip install -U git+https://github.com/Qiskit/qiskit.git
- name: Install openblas
run: |
set -e
sudo apt-get update
sudo apt-get install -y libopenblas-dev
shell: bash
- name: Install Aer
run: |
python -m pip install -U .
- name: Run Tests
run: |
set -e
pip check
rm -rf qiskit_aer
stestr run --slowest
shell: bash

2 changes: 1 addition & 1 deletion qiskit_aer/backends/aer_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _inline_for_loop_op(self, instruction, parent, bit_map):
continue_label = f"{loop_name}_{index}"
inlined_body = self._inline_circuit(body, continue_label, break_label, inner_bit_map)
if loop_parameter is not None:
inlined_body = inlined_body.bind_parameters({loop_parameter: index})
inlined_body = inlined_body.assign_parameters({loop_parameter: index})
parent.append(inlined_body, qargs, cargs)
parent.append(AerMark(continue_label, len(qargs), len(cargs)), qargs, cargs)

Expand Down
2 changes: 1 addition & 1 deletion test/benchmark/simulator_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def add_expval(base, num_terms):
param_binds = {}
for param in circuit.parameters:
param_binds[param] = np.random.random()
circuit = circuit.bind_parameters(param_binds)
circuit = circuit.assign_parameters(param_binds)

simulator = self.simulators[runtime]
if measure == self.MEASUREMENT_SAMPLING:
Expand Down
2 changes: 1 addition & 1 deletion test/terra/backends/aer_simulator/test_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def test_fusion_two_qubits(self):
for param in circuit.parameters:
param_binds[param] = np.random.random()

circuit = transpile(circuit.bind_parameters(param_binds), backend, optimization_level=0)
circuit = transpile(circuit.assign_parameters(param_binds), backend, optimization_level=0)

backend_options = self.fusion_options(enabled=True, threshold=1)
backend_options["fusion_verbose"] = True
Expand Down
4 changes: 2 additions & 2 deletions test/terra/backends/test_parameterized_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def test_run_path_with_truncation(self):
param_map = {theta: [0.1 * i for i in range(3)]}
param_sets = [{theta: 0.1 * i} for i in range(3)]

resolved_circuits = [circuit.bind_parameters(param_set) for param_set in param_sets]
resolved_circuits = [circuit.assign_parameters(param_set) for param_set in param_sets]

result = backend.run(circuit, parameter_binds=[param_map]).result()
self.assertSuccess(result)
Expand Down Expand Up @@ -480,7 +480,7 @@ def test_global_phase_parameters(self):

circs = []
for v in [1, 2, 3]:
circs.append(circ.bind_parameters({theta: v}))
circs.append(circ.assign_parameters({theta: v}))

expected = backend.run(circs, shots=10, seed_simulator=100).result()

Expand Down
2 changes: 1 addition & 1 deletion test/terra/backends/test_runtime_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def test_run_path_with_truncation(self, method, device):
param_map = {theta: [0.1 * i for i in range(3)]}
param_sets = [{theta: 0.1 * i} for i in range(3)]

resolved_circuits = [circuit.bind_parameters(param_set) for param_set in param_sets]
resolved_circuits = [circuit.assign_parameters(param_set) for param_set in param_sets]

result = backend.run(
circuit,
Expand Down
4 changes: 2 additions & 2 deletions test/terra/primitives/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_estimator(self, abelian_grouping):
@data(True, False)
def test_init_observable_from_operator(self, abelian_grouping):
"""test for evaluate without parameters"""
circuit = self.ansatz.bind_parameters([0, 1, 1, 2, 3, 5])
circuit = self.ansatz.assign_parameters([0, 1, 1, 2, 3, 5])
matrix = Operator(
[
[-1.06365335, 0.0, 0.0, 0.1809312],
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_evaluate_multi_params(self, abelian_grouping):
@data(True, False)
def test_evaluate_no_params(self, abelian_grouping):
"""test for evaluate without parameters"""
circuit = self.ansatz.bind_parameters([0, 1, 1, 2, 3, 5])
circuit = self.ansatz.assign_parameters([0, 1, 1, 2, 3, 5])
est = Estimator(abelian_grouping=abelian_grouping)
result = est.run(circuit, self.observable, seed=15, shots=8192).result()
self.assertIsInstance(result, EstimatorResult)
Expand Down

0 comments on commit e7afbfb

Please sign in to comment.