Skip to content

Commit

Permalink
Merge pull request #315 from entropicalabs/fix_cplex_tests
Browse files Browse the repository at this point in the history
Fix CPLEX test workflow on MacOS and Windows + other test fixes
  • Loading branch information
KilianPoirier authored Jun 25, 2024
2 parents 69de0e2 + 8ef25b8 commit dd6131a
Show file tree
Hide file tree
Showing 35 changed files with 185 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Check-out repository
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: 3.9
- name: Log in with Azure
uses: azure/login@v1
with:
Expand All @@ -34,7 +34,7 @@ jobs:
python -m venv env
source env/bin/activate
python -m pip install --upgrade pip
make dev-install-tests
make dev-install-tests-cplex
pip install ipykernel
- name: Setup IBMQ account
env:
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: 3.9

- name: Install OpenQAOA
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_dev_ext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: 3.9
- name: Install qvm
run: |
find /usr/lib -name "libffi.so*"
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
run: |
source env/bin/activate
ipython kernel install --name "env" --user
pytest tests/ src/*/tests/ -v -m 'not (qpu or docker_aws or api or sim or braket_api)'
pytest tests/ src/*/tests/ -v -m 'not (qpu or docker_aws or api or sim or braket_api or cplex)'
docs-ext:
runs-on: ubuntu-latest
Expand All @@ -66,7 +66,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: 3.9

- name: Install OpenQAOA
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_main_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: ['3.8', '3.9', '3.10']
python: ['3.9', '3.10']
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

Expand All @@ -38,7 +38,7 @@ jobs:
python -m venv env
source env/bin/activate
python -m pip install --upgrade pip
make dev-install-tests
make dev-install-tests-cplex
pip install ipykernel
- name: Setup IBMQ account
env:
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: 3.9

- name: Install OpenQAOA
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_main_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.8', '3.9', '3.10']
python: ['3.9', '3.10']
forest-sdk-version: ['2.23.0']

runs-on: macos-latest
Expand Down Expand Up @@ -56,4 +56,4 @@ jobs:
run: |
source env/bin/activate
ipython kernel install --user --name "env"
pytest tests/ src/*/tests -m 'not (qpu or api or docker_aws or braket_api or sim)'
pytest tests/ src/*/tests -m 'not (qpu or api or docker_aws or braket_api or sim or cplex)'
6 changes: 3 additions & 3 deletions .github/workflows/test_main_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.8', '3.9', '3.10']
python: ['3.9', '3.10']
forest-sdk-version: [2.23.0]

# Run on a Windows machine
Expand Down Expand Up @@ -63,5 +63,5 @@ jobs:
run: |
.\env\Scripts\Activate.ps1
ipython kernel install --name "env" --user
pytest tests/ src/*/tests -m 'not (qpu or api or docker_aws or braket_api or sim)'
Get-ChildItem -Directory | ForEach-Object { pytest $_.FullName -m 'not (qpu or api or docker_aws or braket_api or sim)'}
pytest tests/ src/*/tests -m 'not (qpu or api or docker_aws or braket_api or sim or cplex)'
Get-ChildItem -Directory | ForEach-Object { pytest $_.FullName -m 'not (qpu or api or docker_aws or braket_api or sim or cplex)'}
2 changes: 1 addition & 1 deletion .github/workflows/test_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: ['3.8', '3.9', '3.10']
python: ['3.9', '3.10']
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_pypi_prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: ['3.8', '3.9', '3.10', '3.11']
python: ['3.9', '3.10', '3.11']
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ dev-install-tests:
pip install -e ./src/openqaoa-azure
pip install -e .

.PHONY: dev-install-tests-cplex
dev-install-tests-cplex:
pip install -e ./src/openqaoa-core[tests-cplex]
pip install -e ./src/openqaoa-qiskit
pip install -e ./src/openqaoa-pyquil
pip install -e ./src/openqaoa-braket
pip install -e ./src/openqaoa-azure
pip install -e .

.PHONY: dev-install-docs
dev-install-docs:
pip install -e ./src/openqaoa-core[docs]
Expand Down
3 changes: 2 additions & 1 deletion examples/09_RQAOA_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@
"print('terms of of the QUBO problem in recursive step 2: ', problem_2.terms)\n",
"\n",
"#plotting the correlation matrix\n",
"r.result.plot_corr_matrix(step=2)"
"fig, ax = r.result.plot_corr_matrix(step=2)\n",
"fig.show()"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ markers =
docker_aws: marks tests that require to build aws docker (deselect with '-m "not docker_aws"')
braket_api: marks tests that require valid AWS credentials (no QPU) (deselect with '-m "not braket_api"')
notebook: marks tests that run on jupyter noteboks (deselect with '-m "not notebook"')
sim: marks tests that run on remote Simulators (deselect with '-m "not sim"')
sim: marks tests that run on remote Simulators (deselect with '-m "not sim"')
cplex: marks tests that require CPLEX (deselect with '-m "not cplex"')
6 changes: 4 additions & 2 deletions src/openqaoa-core/openqaoa/algorithms/qaoa/qaoa_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ def plot(
1 if one_plot else sum([1 if values[key][0] else 0 for key in values])
)
fig, ax = plt.subplots(nrows=nrows, ncols=1, figsize=(6.5, 5 * nrows))
else:
fig = ax.get_figure()

# plot the requested plots
count_sp = 0 # counter of subplots
Expand Down Expand Up @@ -553,8 +555,8 @@ def plot(
if ax_input is None:
if nrows > 1:
fig.subplots_adjust(hspace=0.3) # add some space between the subplots
plt.show()
plt.close(fig)

return fig, ax

@staticmethod
def __ordered_points(n_params, n_points_axis):
Expand Down
15 changes: 11 additions & 4 deletions src/openqaoa-core/openqaoa/algorithms/rqaoa/rqaoa_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,18 @@ def get_corr_matrix(self, step):
"""
return self["intermediate_steps"][step]["corr_matrix"]

def plot_corr_matrix(self, step, cmap="cool"):
def plot_corr_matrix(self, step, cmap="cool", ax=None):
"""
Plots the correlation matrix of the i-th step of the RQAOA.
TODO : add more options
"""
plt.imshow(self.get_corr_matrix(step=step), cmap=cmap)
plt.colorbar()
plt.show()

if ax is None:
fig, ax = plt.subplots()
else:
fig = ax.get_figure()

Check warning on line 156 in src/openqaoa-core/openqaoa/algorithms/rqaoa/rqaoa_result.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/algorithms/rqaoa/rqaoa_result.py#L156

Added line #L156 was not covered by tests

im = ax.imshow(self.get_corr_matrix(step=step), cmap=cmap)
cbar = ax.figure.colorbar(im, ax=ax)

return fig, ax
7 changes: 3 additions & 4 deletions src/openqaoa-core/openqaoa/problems/bpsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ def plot_paint_sequence(self, paint_sequence, ax=None):
# If no ax (subplot) is provided, create a new figure with the determined width
if ax is None:
fig, ax = plt.subplots(figsize=(fig_width, 2))
else:
fig = ax.get_figure()

Check warning on line 625 in src/openqaoa-core/openqaoa/problems/bpsp.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/problems/bpsp.py#L625

Added line #L625 was not covered by tests

# Plot bars for each car, colored based on the paint_sequence
ax.bar(
Expand All @@ -647,7 +649,4 @@ def plot_paint_sequence(self, paint_sequence, ax=None):
ax.spines["right"].set_visible(False)
ax.spines["left"].set_visible(False)

# If no ax is provided, show the plot directly
if ax is None:
plt.tight_layout()
plt.show()
return fig, ax

Check warning on line 652 in src/openqaoa-core/openqaoa/problems/bpsp.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/problems/bpsp.py#L652

Added line #L652 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def __repr__(self):
"""
String representation of the Gatemap label
"""
representation = f"{self.n_qubits}Q_" if self.n_qubits is not None else ""
n_str = "ONE" if self.n_qubits == 1 else "TWO" if self.n_qubits == 2 else ""
representation = f"{n_str}Q_" if self.n_qubits is not None else ""
representation += f"{self.type.value}" if self.type.value is not None else ""
representation += f"_seq{self.sequence}" if self.sequence is not None else ""
representation += f"_layer{self.layer}" if self.layer is not None else ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ def empty(cls, qaoa_descriptor: QAOADescriptor, total_annealing_time: float):
def plot(self, ax=None, **kwargs):
if ax is None:
fig, ax = plt.subplots()
else:
fig = ax.get_figure()

Check warning on line 159 in src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/annealingparams.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/annealingparams.py#L159

Added line #L159 was not covered by tests

ax.plot(self.schedule, marker="s", **kwargs)
ax.set_xlabel("p", fontsize=14)
ax.set_ylabel("s(t)", fontsize=14)
ax.xaxis.set_major_locator(MaxNLocator(integer=True))

return fig, ax
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ def plot(self, ax=None, **kwargs):

if ax is None:
fig, ax = plt.subplots((n + 1) // 2, 2, figsize=(9, 9 if n > 2 else 5))
else:
fig = ax.get_figure()

Check warning on line 310 in src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/extendedparams.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/extendedparams.py#L310

Added line #L310 was not covered by tests

fig.tight_layout(pad=4.0)

Expand Down Expand Up @@ -342,3 +344,5 @@ def plot(self, ax=None, **kwargs):
ax[1].axis("off")
elif k == 2:
ax[1, 1].axis("off")

return fig, ax
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def plot(self, ax=None, **kwargs):

if ax is None:
fig, ax = plt.subplots(2, figsize=(7, 9))
else:
fig = ax.get_figure()

Check warning on line 202 in src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/fourierparams.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/fourierparams.py#L202

Added line #L202 was not covered by tests

fig.tight_layout(pad=4.0)

Expand All @@ -213,6 +215,8 @@ def plot(self, ax=None, **kwargs):
ax[1].legend()
ax[1].xaxis.set_major_locator(MaxNLocator(integer=True))

return fig, ax


class QAOAVariationalFourierWithBiasParams(QAOAVariationalBaseParams):
"""
Expand Down Expand Up @@ -425,6 +429,8 @@ def plot(self, ax=None, **kwargs):
# "params.u_singles, params.u_pairs")
if ax is None:
fig, ax = plt.subplots(2, figsize=(7, 9))
else:
fig = ax.get_figure()

Check warning on line 433 in src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/fourierparams.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/fourierparams.py#L433

Added line #L433 was not covered by tests

fig.tight_layout(pad=4.0)

Expand Down Expand Up @@ -456,6 +462,8 @@ def plot(self, ax=None, **kwargs):
ax[1].legend()
ax[1].xaxis.set_major_locator(MaxNLocator(integer=True))

return fig, ax


class QAOAVariationalFourierExtendedParams(QAOAVariationalBaseParams):
r"""
Expand Down Expand Up @@ -706,19 +714,6 @@ def empty(cls, qaoa_descriptor: QAOADescriptor, q: int):
return cls(qaoa_descriptor, q, v_singles, v_pairs, u_singles, u_pairs)

def plot(self, ax=None, **kwargs):
# if ax is None:
# fig, ax = plt.subplots()

# ax.plot(dct(self.v, n=self.p, axis=0),
# label="betas", marker="s", ls="", **kwargs)
# if not _is_iterable_empty(self.u_singles):
# ax.plot(dst(self.u_singles, n=self.p),
# label="gammas_singles", marker="^", ls="", **kwargs)
# if not _is_iterable_empty(self.u_pairs):
# ax.plot(dst(self.u_pairs, n=self.p),
# label="gammas_pairs", marker="v", ls="", **kwargs)
# ax.set_xlabel("timestep")
# ax.legend()

betas_singles = dct(self.v_singles, n=self.p, axis=0)
betas_pairs = dct(self.v_pairs, n=self.p, axis=0)
Expand Down Expand Up @@ -767,6 +762,8 @@ def plot(self, ax=None, **kwargs):

if ax is None:
fig, ax = plt.subplots((n + 1) // 2, 2, figsize=(9, 4 * (n + 1) // 2))
else:
fig = ax.get_figure()

Check warning on line 766 in src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/fourierparams.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/fourierparams.py#L766

Added line #L766 was not covered by tests

fig.tight_layout(pad=4.0)

Expand Down Expand Up @@ -803,3 +800,5 @@ def plot(self, ax=None, **kwargs):

if j == 0:
ax[i, j + 1].axis("off")

return fig, ax
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ def empty(cls, qaoa_descriptor: QAOADescriptor):
def plot(self, ax=None, **kwargs):
if ax is None:
fig, ax = plt.subplots()
else:
fig = ax.get_figure()

Check warning on line 166 in src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/standardparams.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/standardparams.py#L166

Added line #L166 was not covered by tests

ax.plot(self.betas, label="betas", marker="s", ls="", **kwargs)
ax.plot(self.gammas, label="gammas", marker="^", ls="", **kwargs)
ax.set_xlabel("p", fontsize=12)
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
ax.legend()

return fig, ax

def convert_to_ext(self, args_std):
"""
Method that converts a list of parameters in the standard parametrisation
Expand Down Expand Up @@ -382,6 +386,8 @@ def empty(cls, qaoa_descriptor: QAOADescriptor):
def plot(self, ax=None, **kwargs):
if ax is None:
fig, ax = plt.subplots()
else:
fig = ax.get_figure()

Check warning on line 390 in src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/standardparams.py

View check run for this annotation

Codecov / codecov/patch

src/openqaoa-core/openqaoa/qaoa_components/variational_parameters/standardparams.py#L390

Added line #L390 was not covered by tests

ax.plot(self.betas, label="betas", marker="s", ls="", **kwargs)
if not _is_iterable_empty(self.gammas_singles):
Expand All @@ -396,3 +402,5 @@ def plot(self, ax=None, **kwargs):
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
# ax.grid(linestyle='--')
ax.legend()

return fig, ax
Loading

0 comments on commit dd6131a

Please sign in to comment.